From aa09943d1032e678e359f4f4422e6ff7a7bb1e12 Mon Sep 17 00:00:00 2001 From: annapoorna-s-alt Date: Thu, 12 Sep 2024 05:21:22 +0000 Subject: [PATCH] CRAYSAT-1902: Update `sat bootprep` with new changes of cfs v2 Here, we update the `sat bootprep` to use only cfs v2 and will not break any changes Also update the session check of `sat bootsys` to validate cfs v2 sessions Update latest csm-api-client --- CHANGELOG.md | 5 +++++ sat/apiclient/__init__.py | 4 ++-- sat/cli/bootprep/image.py | 6 +++--- sat/cli/bootprep/input/configuration.py | 6 +++--- sat/cli/bootprep/input/image.py | 4 ++-- sat/cli/bootprep/input/instance.py | 4 ++-- sat/cli/bootprep/input/session_template.py | 8 ++++---- sat/cli/bootprep/main.py | 6 +++--- sat/cli/bootsys/service_activity.py | 6 +++--- tests/cli/bootprep/input/test_configuration.py | 6 +++--- tests/cli/bootprep/input/test_image.py | 6 +++--- tests/cli/bootprep/test_main.py | 4 ++-- tests/cli/bootsys/test_service_activity.py | 2 +- 13 files changed, 36 insertions(+), 31 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 03ab6b42..8f13c978 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -25,6 +25,11 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). +## [3.32.1] - 2024-09-17 + +### Changed +- Changed `sat bootprep` and `sat bootsys` to use the CFS.V2 updated classes from `csm-api-client` + ## [3.32.0] - 2024-09-11 ### Added diff --git a/sat/apiclient/__init__.py b/sat/apiclient/__init__.py index 050501d8..3c1272cf 100644 --- a/sat/apiclient/__init__.py +++ b/sat/apiclient/__init__.py @@ -1,7 +1,7 @@ # # MIT License # -# (C) Copyright 2019-2023 Hewlett Packard Enterprise Development LP +# (C) Copyright 2019-2024 Hewlett Packard Enterprise Development LP # # Permission is hereby granted, free of charge, to any person obtaining a # copy of this software and associated documentation files (the "Software"), @@ -26,7 +26,7 @@ """ # Import these names so that they can still be imported from the apiclient package directly -from csm_api_client.service.cfs import CFSClient +from csm_api_client.service.cfs import CFSClientBase from csm_api_client.service.gateway import APIError, APIGatewayClient, ReadTimeout from csm_api_client.service.hsm import HSMClient diff --git a/sat/cli/bootprep/image.py b/sat/cli/bootprep/image.py index cc95435f..76f914bc 100644 --- a/sat/cli/bootprep/image.py +++ b/sat/cli/bootprep/image.py @@ -1,7 +1,7 @@ # # MIT License # -# (C) Copyright 2021-2023 Hewlett Packard Enterprise Development LP +# (C) Copyright 2021-2024 Hewlett Packard Enterprise Development LP # # Permission is hereby granted, free of charge, to any person obtaining a # copy of this software and associated documentation files (the "Software"), @@ -330,7 +330,7 @@ def validate_image_configurations(input_images, cfs_client, input_config_names, Args: input_images (list of sat.cli.bootprep.input.image.InputImage): the IMSImages which should have their configurations validated. - cfs_client (csm_api_client.service.cfs.CFSClient): the CFS client to query to + cfs_client (csm_api_client.service.cfs.CFSClientBase): the CFS client to query to determine whether the configuration for the image exists. input_config_names (list of str): the list of configuration names that are defined in the input file @@ -423,7 +423,7 @@ def validate_images(instance, args, cfs_client): against the schema. args: The argparse.Namespace object containing the parsed arguments passed to the bootprep subcommand. - cfs_client (csm_api_client.service.cfs.CFSClient): the CFS API client to make + cfs_client (csm_api_client.service.cfs.CFSClientBase): the CFS API client to make requests to the CFS API Returns: None diff --git a/sat/cli/bootprep/input/configuration.py b/sat/cli/bootprep/input/configuration.py index b1e1fc70..f3387217 100644 --- a/sat/cli/bootprep/input/configuration.py +++ b/sat/cli/bootprep/input/configuration.py @@ -1,7 +1,7 @@ # # MIT License # -# (C) Copyright 2021-2023 Hewlett Packard Enterprise Development LP +# (C) Copyright 2021-2024 Hewlett Packard Enterprise Development LP # # Permission is hereby granted, free of charge, to any person obtaining a # copy of this software and associated documentation files (the "Software"), @@ -371,7 +371,7 @@ def __init__(self, data, instance, index, jinja_env, cfs_client, index (int): the index of the item in the collection in the instance jinja_env (jinja2.Environment): the Jinja2 environment in which fields supporting Jinja2 templating should be rendered. - cfs_client (csm_api_client.service.cfs.CFSClient): the CFS API client + cfs_client (csm_api_client.service.cfs.CFSClientBase): the CFS API client product_catalog (cray_product_catalog.query.ProductCatalog): the product catalog object **kwargs: additional keyword arguments @@ -466,7 +466,7 @@ def __init__(self, items_data, instance, jinja_env, request_dumper, cfs_client, fields supporting Jinja2 templating should be rendered. request_dumper (sat.cli.bootprep.output.RequestDumper): the dumper for dumping request data to files. - cfs_client (csm_api_client.service.cfs.CFSClient): the CFS API client + cfs_client (csm_api_client.service.cfs.CFSClientBase): the CFS API client **kwargs: additional keyword arguments """ super().__init__(items_data, instance, jinja_env, request_dumper, diff --git a/sat/cli/bootprep/input/image.py b/sat/cli/bootprep/input/image.py index 762acf41..9c5ae594 100644 --- a/sat/cli/bootprep/input/image.py +++ b/sat/cli/bootprep/input/image.py @@ -55,7 +55,7 @@ class BaseInputImage(DependencyGroupMember, ABC): image_data (dict): the data for an image from the bootprep input file ims_client (sat.apiclient.IMSClient): the IMSClient to make requests to the IMS API - cfs_client (csm_api_client.service.cfs.CFSClient): the CFSClient to make requests to + cfs_client (csm_api_client.service.cfs.CFSClientBase): the CFSClient to make requests to the CFS API public_key_id (str): the id of the public key in IMS to use when building the image @@ -94,7 +94,7 @@ def __init__(self, image_data, index, instance, jinja_env, product_catalog, ims_ the product catalog object ims_client (sat.apiclient.IMSClient): the IMS API client to make requests to the IMS API - cfs_client (csm_api_client.service.cfs.CFSClient): the CFS API client to make + cfs_client (csm_api_client.service.cfs.CFSClientBase): the CFS API client to make requests to the CFS API """ super().__init__() diff --git a/sat/cli/bootprep/input/instance.py b/sat/cli/bootprep/input/instance.py index 4a1d98fe..ed123126 100644 --- a/sat/cli/bootprep/input/instance.py +++ b/sat/cli/bootprep/input/instance.py @@ -1,7 +1,7 @@ # # MIT License # -# (C) Copyright 2021-2023 Hewlett Packard Enterprise Development LP +# (C) Copyright 2021-2024 Hewlett Packard Enterprise Development LP # # Permission is hereby granted, free of charge, to any person obtaining a # copy of this software and associated documentation files (the "Software"), @@ -45,7 +45,7 @@ def __init__(self, instance_dict, request_dumper, the instance has already been validated against the schema. request_dumper (sat.cli.bootprep.output.RequestDumper): the dumper for dumping request data to files. - cfs_client (csm_api_client.service.cfs.CFSClient): the CFS API client to make + cfs_client (csm_api_client.service.cfs.CFSClientBase): the CFS API client to make requests to the CFS API ims_client (sat.apiclient.IMSClient): the IMS API client to make requests to the IMS API diff --git a/sat/cli/bootprep/input/session_template.py b/sat/cli/bootprep/input/session_template.py index 50efff80..9e05f225 100644 --- a/sat/cli/bootprep/input/session_template.py +++ b/sat/cli/bootprep/input/session_template.py @@ -1,7 +1,7 @@ # # MIT License # -# (C) Copyright 2021-2023 Hewlett Packard Enterprise Development LP +# (C) Copyright 2021-2024 Hewlett Packard Enterprise Development LP # # Permission is hereby granted, free of charge, to any person obtaining a # copy of this software and associated documentation files (the "Software"), @@ -52,7 +52,7 @@ class InputSessionTemplate(BaseInputItem): requests to the BOS API ims_client (sat.apiclient.IMSClient): the IMS API client to make requests to the IMS API - cfs_client (csm_api_client.service.cfs.CFSClient): the CFS API client to make + cfs_client (csm_api_client.service.cfs.CFSClientBase): the CFS API client to make requests to the CFS API """ description = 'BOS session template' @@ -70,7 +70,7 @@ def __init__(self, data, instance, index, jinja_env, bos_client, cfs_client, ims jinja_env (jinja2.Environment): the Jinja2 environment in which fields supporting Jinja2 templating should be rendered. bos_client (sat.apiclient.BOSClientCommon): the BOS API client - cfs_client (csm_api_client.service.cfs.CFSClient): the CFS API client + cfs_client (csm_api_client.service.cfs.CFSClientBase): the CFS API client ims_client (sat.apiclient.IMSClient): the IMS API client **kwargs: additional keyword arguments """ @@ -398,7 +398,7 @@ def __init__(self, items_data, instance, jinja_env, request_dumper, request_dumper (sat.cli.bootprep.output.RequestDumper): the dumper for dumping request data to files. bos_client (sat.apiclient.BOSClientCommon): the BOS API client - cfs_client (csm_api_client.service.cfs.CFSClient): the CFS API client + cfs_client (csm_api_client.service.cfs.CFSClientBase): the CFS API client ims_client (sat.apiclient.IMSClient): the IMS API client **kwargs: additional keyword arguments """ diff --git a/sat/cli/bootprep/main.py b/sat/cli/bootprep/main.py index dac46722..e9869be9 100644 --- a/sat/cli/bootprep/main.py +++ b/sat/cli/bootprep/main.py @@ -1,7 +1,7 @@ # # MIT License # -# (C) Copyright 2021-2023 Hewlett Packard Enterprise Development LP +# (C) Copyright 2021-2024 Hewlett Packard Enterprise Development LP # # Permission is hereby granted, free of charge, to any person obtaining a # copy of this software and associated documentation files (the "Software"), @@ -32,7 +32,7 @@ from jinja2.sandbox import SandboxedEnvironment import yaml -from sat.apiclient import CFSClient, IMSClient +from sat.apiclient import CFSClientBase, IMSClient from sat.apiclient.bos import BOSClientCommon from sat.cli.bootprep.errors import ( BootPrepDocsError, @@ -210,7 +210,7 @@ def do_bootprep_run(schema_validator, args): LOGGER.info('Input file successfully validated against schema') session = SATSession() - cfs_client = CFSClient(session) + cfs_client = CFSClientBase.get_cfs_client(session, 'v2') ims_client = IMSClient(session) # CASMTRIAGE-4288: IMS can be extremely slow to return DELETE requests for # large images, so this IMSClient will not use a timeout on HTTP requests diff --git a/sat/cli/bootsys/service_activity.py b/sat/cli/bootsys/service_activity.py index 3d58b770..fa28fef0 100644 --- a/sat/cli/bootsys/service_activity.py +++ b/sat/cli/bootsys/service_activity.py @@ -1,7 +1,7 @@ # # MIT License # -# (C) Copyright 2020-2023 Hewlett Packard Enterprise Development LP +# (C) Copyright 2020-2024 Hewlett Packard Enterprise Development LP # # Permission is hereby granted, free of charge, to any person obtaining a # copy of this software and associated documentation files (the "Software"), @@ -38,7 +38,7 @@ from sat.apiclient import ( APIError, - CFSClient, + CFSClientBase, NMDClient ) from sat.apiclient.bos import BOSClientCommon @@ -383,7 +383,7 @@ def get_active_sessions(self): Raises: ServiceCheckError: if unable to get the active CFS sessions. """ - cfs_client = CFSClient(SATSession()) + cfs_client = CFSClientBase.get_cfs_client(SATSession(), 'v2') try: sessions = cfs_client.get('sessions').json() except (APIError, ValueError) as err: diff --git a/tests/cli/bootprep/input/test_configuration.py b/tests/cli/bootprep/input/test_configuration.py index f7811add..e127a228 100644 --- a/tests/cli/bootprep/input/test_configuration.py +++ b/tests/cli/bootprep/input/test_configuration.py @@ -1,7 +1,7 @@ # # MIT License # -# (C) Copyright 2021-2023 Hewlett Packard Enterprise Development LP +# (C) Copyright 2021-2024 Hewlett Packard Enterprise Development LP # # Permission is hereby granted, free of charge, to any person obtaining a # copy of this software and associated documentation files (the "Software"), @@ -34,7 +34,7 @@ from csm_api_client.service.vcs import VCSError from jinja2.sandbox import SandboxedEnvironment -from csm_api_client.service.cfs import CFSClient +from csm_api_client.service.cfs import CFSClientBase from sat.cli.bootprep.errors import InputItemCreateError from sat.cli.bootprep.input.configuration import ( AdditionalInventory, @@ -617,7 +617,7 @@ def setUp(self): self.mock_instance = Mock(spec=InputInstance) # Fake index of configuration data in an input file self.index = 0 - self.mock_cfs_client = Mock(spep=CFSClient) + self.mock_cfs_client = Mock(spep=CFSClientBase) def tearDown(self): patch.stopall() diff --git a/tests/cli/bootprep/input/test_image.py b/tests/cli/bootprep/input/test_image.py index 8b8d6259..dc9544bd 100644 --- a/tests/cli/bootprep/input/test_image.py +++ b/tests/cli/bootprep/input/test_image.py @@ -1,7 +1,7 @@ # # MIT License # -# (C) Copyright 2023 Hewlett Packard Enterprise Development LP +# (C) Copyright 2023-2024 Hewlett Packard Enterprise Development LP # # Permission is hereby granted, free of charge, to any person obtaining a # copy of this software and associated documentation files (the "Software"), @@ -26,7 +26,7 @@ from unittest.mock import Mock, patch from cray_product_catalog.query import InstalledProductVersion, ProductCatalog -from csm_api_client.service.cfs import CFSClient +from csm_api_client.service.cfs import CFSClientBase from jinja2 import Environment from sat.apiclient.ims import IMSClient @@ -64,7 +64,7 @@ def setUp(self): self.jinja_env = Environment() self.jinja_env.globals = {self.product_name: {'version': self.product_version}} - self.mock_cfs_client = Mock(spec=CFSClient) + self.mock_cfs_client = Mock(spec=CFSClientBase) self.mock_ims_client = Mock(spec=IMSClient) # The IMS resources should have the same info as in the product catalog entries diff --git a/tests/cli/bootprep/test_main.py b/tests/cli/bootprep/test_main.py index 833ed858..fce2c136 100644 --- a/tests/cli/bootprep/test_main.py +++ b/tests/cli/bootprep/test_main.py @@ -1,7 +1,7 @@ # # MIT License # -# (C) Copyright 2021-2023 Hewlett Packard Enterprise Development LP +# (C) Copyright 2021-2024 Hewlett Packard Enterprise Development LP # # Permission is hereby granted, free of charge, to any person obtaining a # copy of this software and associated documentation files (the "Software"), @@ -131,7 +131,7 @@ def setUp(self): self.mock_input_instance_cls = patch('sat.cli.bootprep.main.InputInstance').start() self.mock_input_instance = self.mock_input_instance_cls.return_value self.mock_sat_session = patch('sat.cli.bootprep.main.SATSession').start() - self.mock_cfs_client = patch('sat.cli.bootprep.main.CFSClient').start().return_value + self.mock_cfs_client = patch('sat.cli.bootprep.main.CFSClientBase.get_cfs_client').start().return_value self.mock_ims_client = patch('sat.cli.bootprep.main.IMSClient').start().return_value self.mock_bos_client = patch('sat.cli.bootprep.main.BOSClientCommon.get_bos_client').start().return_value self.mock_configurations = self.mock_input_instance.input_configurations diff --git a/tests/cli/bootsys/test_service_activity.py b/tests/cli/bootsys/test_service_activity.py index 5b101c6c..3a82432e 100644 --- a/tests/cli/bootsys/test_service_activity.py +++ b/tests/cli/bootsys/test_service_activity.py @@ -508,7 +508,7 @@ def json(): patch('sat.cli.bootsys.service_activity.SATSession').start() self.mock_cfs_client = patch( - 'sat.cli.bootsys.service_activity.CFSClient').start() + 'sat.cli.bootsys.service_activity.CFSClientBase.get_cfs_client').start() self.mock_cfs_client.return_value.get = mock_cfs_get def tearDown(self):