From e5039d9542b4561091af7a4680b14e2c62f4bde0 Mon Sep 17 00:00:00 2001 From: Hemanth Nakkina Date: Fri, 10 Jan 2025 15:13:49 +0530 Subject: [PATCH] Fix lint issues --- sunbeam-python/sunbeam/commands/launch.py | 2 +- sunbeam-python/sunbeam/core/common.py | 2 +- sunbeam-python/sunbeam/core/juju.py | 14 ++++----- sunbeam-python/sunbeam/core/terraform.py | 14 ++++----- sunbeam-python/sunbeam/feature_manager.py | 5 +--- .../sunbeam/features/interface/utils.py | 2 +- .../sunbeam/features/validation/feature.py | 2 +- .../sunbeam/features/vault/feature.py | 8 ++--- sunbeam-python/sunbeam/provider/maas/steps.py | 8 ++--- sunbeam-python/sunbeam/steps/juju.py | 30 +++++++++---------- sunbeam-python/sunbeam/steps/microceph.py | 2 +- 11 files changed, 43 insertions(+), 46 deletions(-) diff --git a/sunbeam-python/sunbeam/commands/launch.py b/sunbeam-python/sunbeam/commands/launch.py index bcf403e6..e66ffa5c 100644 --- a/sunbeam-python/sunbeam/commands/launch.py +++ b/sunbeam-python/sunbeam/commands/launch.py @@ -114,7 +114,7 @@ def launch( instance_name = name if name else petname.Generate() image = conn.compute.find_image(image_name) flavor = conn.compute.find_flavor("m1.tiny") - network = conn.network.find_network(f'{tf_output["OS_USERNAME"]}-network') + network = conn.network.find_network(f"{tf_output['OS_USERNAME']}-network") keypair = conn.compute.find_keypair(key) server = conn.compute.create_server( name=instance_name, diff --git a/sunbeam-python/sunbeam/core/common.py b/sunbeam-python/sunbeam/core/common.py index 5b869993..9a9cde05 100644 --- a/sunbeam-python/sunbeam/core/common.py +++ b/sunbeam-python/sunbeam/core/common.py @@ -161,7 +161,7 @@ def __init__(self, result_type: ResultType = ResultType.COMPLETED, **kwargs): # attribute. if hasattr(self, key): raise ValueError( - f"{key} was specified but already exists on " f"this StepResult." + f"{key} was specified but already exists on this StepResult." ) self.__setattr__(key, value) diff --git a/sunbeam-python/sunbeam/core/juju.py b/sunbeam-python/sunbeam/core/juju.py index bc77f794..07a49595 100644 --- a/sunbeam-python/sunbeam/core/juju.py +++ b/sunbeam-python/sunbeam/core/juju.py @@ -996,7 +996,7 @@ async def wait_units_gone( ) except asyncio.TimeoutError as e: raise TimeoutException( - "Timed out while waiting for units " f"{', '.join(name_set)} to be gone" + f"Timed out while waiting for units {', '.join(name_set)} to be gone" ) from e async def wait_units_ready( @@ -1491,7 +1491,7 @@ def _juju_cmd(self, *args): cmd.extend(args) cmd.extend(["--format", "json"]) - LOG.debug(f'Running command {" ".join(cmd)}') + LOG.debug(f"Running command {' '.join(cmd)}") process = subprocess.run(cmd, capture_output=True, text=True, check=True) LOG.debug(f"Command finished. stdout={process.stdout}, stderr={process.stderr}") @@ -1628,7 +1628,7 @@ def add_cloud(self, name: str, cloud: dict, controller: str | None) -> bool: ] if controller: cmd.extend(["--controller", controller, "--force"]) - LOG.debug(f'Running command {" ".join(cmd)}') + LOG.debug(f"Running command {' '.join(cmd)}") process = subprocess.run(cmd, capture_output=True, text=True, check=True) LOG.debug( f"Command finished. stdout={process.stdout}, stderr={process.stderr}" @@ -1651,7 +1651,7 @@ def add_k8s_cloud_in_client(self, name: str, kubeconfig: dict): env = os.environ.copy() env.update({"KUBECONFIG": temp.name}) - LOG.debug(f'Running command {" ".join(cmd)}') + LOG.debug(f"Running command {' '.join(cmd)}") process = subprocess.run( cmd, capture_output=True, text=True, check=True, env=env ) @@ -1679,7 +1679,7 @@ def add_credential(self, cloud: str, credential: dict, controller: str | None): cmd.extend(["--controller", controller]) else: cmd.extend(["--client"]) - LOG.debug(f'Running command {" ".join(cmd)}') + LOG.debug(f"Running command {' '.join(cmd)}") process = subprocess.run(cmd, capture_output=True, text=True, check=True) LOG.debug( f"Command finished. stdout={process.stdout}, stderr={process.stderr}" @@ -1702,7 +1702,7 @@ def integrate( requirer, ] try: - LOG.debug(f'Running command {" ".join(cmd)}') + LOG.debug(f"Running command {' '.join(cmd)}") process = subprocess.run(cmd, capture_output=True, text=True, check=True) LOG.debug( f"Command finished. stdout={process.stdout}, stderr={process.stderr}" @@ -1722,7 +1722,7 @@ def remove_relation(self, model: str, provider: str, requirer: str): provider, requirer, ] - LOG.debug(f'Running command {" ".join(cmd)}') + LOG.debug(f"Running command {' '.join(cmd)}") process = subprocess.run(cmd, capture_output=True, text=True, check=True) LOG.debug(f"Command finished. stdout={process.stdout}, stderr={process.stderr}") diff --git a/sunbeam-python/sunbeam/core/terraform.py b/sunbeam-python/sunbeam/core/terraform.py index 02234a71..8046f7c9 100644 --- a/sunbeam-python/sunbeam/core/terraform.py +++ b/sunbeam-python/sunbeam/core/terraform.py @@ -169,7 +169,7 @@ def init(self) -> None: if backend_updated: LOG.debug("Backend updated, running terraform init -reconfigure") cmd.append("-reconfigure") - LOG.debug(f'Running command {" ".join(cmd)}') + LOG.debug(f"Running command {' '.join(cmd)}") process = subprocess.run( cmd, capture_output=True, @@ -203,7 +203,7 @@ def apply(self, extra_args: list | None = None): cmd.extend(["-auto-approve", "-no-color"]) if self.parallelism is not None: cmd.append(f"-parallelism={self.parallelism}") - LOG.debug(f'Running command {" ".join(cmd)}') + LOG.debug(f"Running command {' '.join(cmd)}") process = subprocess.run( cmd, capture_output=True, @@ -241,7 +241,7 @@ def destroy(self): ] if self.parallelism is not None: cmd.append(f"-parallelism={self.parallelism}") - LOG.debug(f'Running command {" ".join(cmd)}') + LOG.debug(f"Running command {' '.join(cmd)}") process = subprocess.run( cmd, capture_output=True, @@ -270,7 +270,7 @@ def output(self, hide_output: bool = False) -> dict: try: cmd = [self.terraform, "output", "-json", "-no-color"] - LOG.debug(f'Running command {" ".join(cmd)}') + LOG.debug(f"Running command {' '.join(cmd)}") process = subprocess.run( cmd, capture_output=True, @@ -306,7 +306,7 @@ def pull_state(self) -> dict: try: cmd = [self.terraform, "state", "pull"] - LOG.debug(f'Running command {" ".join(cmd)}') + LOG.debug(f"Running command {' '.join(cmd)}") process = subprocess.run( cmd, capture_output=True, @@ -335,7 +335,7 @@ def state_list(self) -> list: try: cmd = [self.terraform, "state", "list"] - LOG.debug(f'Running command {" ".join(cmd)}') + LOG.debug(f"Running command {' '.join(cmd)}") process = subprocess.run( cmd, capture_output=True, @@ -365,7 +365,7 @@ def state_rm(self, resource: str) -> None: try: cmd = [self.terraform, "state", "rm", resource] - LOG.debug(f'Running command {" ".join(cmd)}') + LOG.debug(f"Running command {' '.join(cmd)}") process = subprocess.run( cmd, capture_output=True, diff --git a/sunbeam-python/sunbeam/feature_manager.py b/sunbeam-python/sunbeam/feature_manager.py index e8d6ee4d..5285ffbb 100644 --- a/sunbeam-python/sunbeam/feature_manager.py +++ b/sunbeam-python/sunbeam/feature_manager.py @@ -263,9 +263,6 @@ def update_features( p.upgrade_hook(deployment, upgrade_release=upgrade_release) except TypeError: LOG.debug( - ( - f"Feature {p.name} does not support upgrades " - "between channels" - ) + f"Feature {p.name} does not support upgrades between channels" ) p.upgrade_hook(deployment) diff --git a/sunbeam-python/sunbeam/features/interface/utils.py b/sunbeam-python/sunbeam/features/interface/utils.py index cd5a5b6e..30c71d53 100644 --- a/sunbeam-python/sunbeam/features/interface/utils.py +++ b/sunbeam-python/sunbeam/features/interface/utils.py @@ -93,7 +93,7 @@ def validate_ca_chain( chain_bytes = base64.b64decode(value) chain_list = re.findall( pattern=( - "(?=-----BEGIN CERTIFICATE-----)(.*?)" "(?<=-----END CERTIFICATE-----)" + "(?=-----BEGIN CERTIFICATE-----)(.*?)(?<=-----END CERTIFICATE-----)" ), string=chain_bytes.decode(), flags=re.DOTALL, diff --git a/sunbeam-python/sunbeam/features/validation/feature.py b/sunbeam-python/sunbeam/features/validation/feature.py index c6bf4026..cdeeb121 100644 --- a/sunbeam-python/sunbeam/features/validation/feature.py +++ b/sunbeam-python/sunbeam/features/validation/feature.py @@ -78,7 +78,7 @@ class Profile(pydantic.BaseModel): DEFAULT_PROFILE = Profile( name="refstack", help=( - "Tests that are part of the RefStack project " "https://refstack.openstack.org/" + "Tests that are part of the RefStack project https://refstack.openstack.org/" ), params={"test-list": "refstack-2022.11"}, ) diff --git a/sunbeam-python/sunbeam/features/vault/feature.py b/sunbeam-python/sunbeam/features/vault/feature.py index 716695d4..c8ebd021 100644 --- a/sunbeam-python/sunbeam/features/vault/feature.py +++ b/sunbeam-python/sunbeam/features/vault/feature.py @@ -126,7 +126,7 @@ def get_vault_status(self, unit: str) -> dict: "-tls-skip-verify", "-format=json", ] - LOG.debug(f'Running vault command: {" ".join(cmd)}') + LOG.debug(f"Running vault command: {' '.join(cmd)}") result = self._run_command_on_container(unit, cmd) LOG.debug(f"Vault command result: {result}") return json.loads(result.get("stdout")) @@ -149,7 +149,7 @@ def initialize_vault(self, unit: str, key_shares: int, key_threshold: int) -> di "-tls-skip-verify", "-format=json", ] - LOG.debug(f'Running vault command: {" ".join(cmd)}') + LOG.debug(f"Running vault command: {' '.join(cmd)}") result = self._run_command_on_container(unit, cmd) # Do not log result since the result has secret keys LOG.debug(f"Vault command result code: {result['return-code']}") @@ -175,7 +175,7 @@ def unseal_vault(self, unit: str, key: str) -> dict: "-format=json", key, ] - LOG.debug(f'Running vault command: {" ".join(cmd[:-1])}') + LOG.debug(f"Running vault command: {' '.join(cmd[:-1])}") result = self._run_command_on_container(unit, cmd) LOG.debug(f"Vault command result: {result}") if result["return-code"] != 0: @@ -201,7 +201,7 @@ def create_token(self, unit: str, root_token: str) -> dict: "-format=json", ] env = {"VAULT_TOKEN": root_token} - LOG.debug(f'Running vault command: {" ".join(cmd)}') + LOG.debug(f"Running vault command: {' '.join(cmd)}") result = self._run_command_on_container(unit, cmd, env) # Do not log result since the result has root token LOG.debug(f"Vault command result code: {result.get('return-code')}") diff --git a/sunbeam-python/sunbeam/provider/maas/steps.py b/sunbeam-python/sunbeam/provider/maas/steps.py index 66c9e9ca..abf7a863 100644 --- a/sunbeam-python/sunbeam/provider/maas/steps.py +++ b/sunbeam-python/sunbeam/provider/maas/steps.py @@ -311,9 +311,9 @@ def run(self) -> DiagnosticsResult: diagnostics=textwrap.dedent( f"""\ A machine needs to be in spaces to be a part of an openstack - deployment. Given machine has roles: {', '.join(assigned_roles)}, + deployment. Given machine has roles: {", ".join(assigned_roles)}, and therefore needs to be a part of the following spaces: - {', '.join(required_spaces)}.""" + {", ".join(required_spaces)}.""" ), machine=self.machine["hostname"], ) @@ -551,7 +551,7 @@ def run(self) -> DiagnosticsResult: {memory_min}MB RAM to be a part of an openstack deployment. Either add more cores and memory to the machine or remove the machine from the deployment. - {self.machine['hostname']}: + {self.machine["hostname"]}: roles: {self.machine["roles"]} cores: {self.machine["cores"]} memory: {self.machine["memory"]}MB""" @@ -690,7 +690,7 @@ def run(self) -> DiagnosticsResult: diagnostics = textwrap.dedent( f"""\ A deployment needs to have either 1 zone or more than 2 zones. - Current zones: {', '.join(self.zones)} + Current zones: {", ".join(self.zones)} """ ) if nb_zones == 0: diff --git a/sunbeam-python/sunbeam/steps/juju.py b/sunbeam-python/sunbeam/steps/juju.py index 218f7c5d..8cfed24c 100644 --- a/sunbeam-python/sunbeam/steps/juju.py +++ b/sunbeam-python/sunbeam/steps/juju.py @@ -303,7 +303,7 @@ def run(self, status: Status | None = None) -> Result: arg = "=".join((option, "********")) hidden_cmd.append(arg) - LOG.debug(f'Running command {" ".join(hidden_cmd)}') + LOG.debug(f"Running command {' '.join(hidden_cmd)}") env = os.environ.copy() env.update(self.proxy_settings) @@ -345,7 +345,7 @@ def run(self, status: Status | None = None) -> Result: str(self.n), *self.extra_args, ] - LOG.debug(f'Running command {" ".join(cmd)}') + LOG.debug(f"Running command {' '.join(cmd)}") process = subprocess.run(cmd, capture_output=True, text=True, check=True) LOG.debug(f"Command finished. stdout={process.stdout}, stderr={process.stderr}") cmd = [ @@ -360,7 +360,7 @@ def run(self, status: Status | None = None) -> Result: ] self.update_status(status, "scaling controller") LOG.debug("Waiting for HA to be enabled") - LOG.debug(f'Running command {" ".join(cmd)}') + LOG.debug(f"Running command {' '.join(cmd)}") process = subprocess.run(cmd, capture_output=True, text=True, check=True) LOG.debug(f"Command finished. stdout={process.stdout}, stderr={process.stderr}") return Result(ResultType.COMPLETED) @@ -456,7 +456,7 @@ def run(self, status: Status | None = None) -> Result: """ try: cmd = [self._get_juju_binary(), "add-user", self.username] - LOG.debug(f'Running command {" ".join(cmd)}') + LOG.debug(f"Running command {' '.join(cmd)}") process = subprocess.run(cmd, capture_output=True, text=True, check=True) LOG.debug( f"Command finished. stdout={process.stdout}, stderr={process.stderr}" @@ -473,7 +473,7 @@ def run(self, status: Status | None = None) -> Result: # Grant superuser access to user. cmd = [self._get_juju_binary(), "grant", self.username, "superuser"] - LOG.debug(f'Running command {" ".join(cmd)}') + LOG.debug(f"Running command {' '.join(cmd)}") process = subprocess.run(cmd, capture_output=True, text=True, check=True) LOG.debug( f"Command finished. stdout={process.stdout}, stderr={process.stderr}" @@ -488,7 +488,7 @@ def run(self, status: Status | None = None) -> Result: "admin", CONTROLLER_MODEL, ] - LOG.debug(f'Running command {" ".join(cmd)}') + LOG.debug(f"Running command {' '.join(cmd)}") process = subprocess.run(cmd, capture_output=True, text=True, check=True) LOG.debug( f"Command finished. stdout={process.stdout}, stderr={process.stderr}" @@ -536,7 +536,7 @@ def run(self, status: Status | None = None) -> Result: "admin", model_with_owner, ] - LOG.debug(f'Running command {" ".join(cmd)}') + LOG.debug(f"Running command {' '.join(cmd)}") process = subprocess.run(cmd, capture_output=True, text=True, check=True) LOG.debug( f"Command finished. stdout={process.stdout}, stderr={process.stderr}" @@ -594,7 +594,7 @@ def run(self, status: Status | None = None) -> Result: """ try: cmd = [self._get_juju_binary(), "remove-user", self.username, "--yes"] - LOG.debug(f'Running command {" ".join(cmd)}') + LOG.debug(f"Running command {' '.join(cmd)}") process = subprocess.run(cmd, capture_output=True, text=True, check=True) LOG.debug( f"Command finished. stdout={process.stdout}, stderr={process.stderr}" @@ -699,7 +699,7 @@ def run(self, status: Status | None = None) -> Result: self.controller, "--no-prompt", ] - LOG.debug(f'Running command {" ".join(cmd)}') + LOG.debug(f"Running command {' '.join(cmd)}") process = subprocess.run( cmd, capture_output=True, text=True, check=True ) @@ -901,7 +901,7 @@ def run(self, status: Status | None = None) -> Result: self.controller, "--no-prompt", ] - LOG.debug(f'Running command {" ".join(cmd)}') + LOG.debug(f"Running command {' '.join(cmd)}") process = subprocess.run(cmd, capture_output=True, text=True, check=True) LOG.debug( f"Command finished. stdout={process.stdout}, stderr={process.stderr}" @@ -1080,7 +1080,7 @@ def run(self, status: Status | None = None) -> Result: str(self.machine_id), "--no-prompt", ] - LOG.debug(f'Running command {" ".join(cmd)}') + LOG.debug(f"Running command {' '.join(cmd)}") process = subprocess.run(cmd, capture_output=True, text=True, check=True) LOG.debug( f"Command finished. stdout={process.stdout}, stderr={process.stderr}" @@ -1600,7 +1600,7 @@ def run(self, status: Status | None = None) -> Result: "--base", JUJU_BASE, ] - LOG.debug(f'Running command {" ".join(cmd)}') + LOG.debug(f"Running command {' '.join(cmd)}") env = os.environ.copy() env.update(self.proxy_settings) process = subprocess.run( @@ -1928,7 +1928,7 @@ def run(self, status: Status | None = None) -> Result: """Switch to juju controller.""" try: cmd = [self._get_juju_binary(), "switch", self.controller] - LOG.debug(f'Running command {" ".join(cmd)}') + LOG.debug(f"Running command {' '.join(cmd)}") process = subprocess.run(cmd, capture_output=True, text=True, check=True) LOG.debug( f"Command finished. stdout={process.stdout}, stderr={process.stderr}" @@ -2156,7 +2156,7 @@ def __init__( def _switch_controller(self, controller: str): cmd = [self._get_juju_binary(), "switch", controller] - LOG.debug(f'Running command {" ".join(cmd)}') + LOG.debug(f"Running command {' '.join(cmd)}") process = subprocess.run(cmd, capture_output=True, text=True, check=True) LOG.debug(f"Command finished. stdout={process.stdout}, stderr={process.stderr}") @@ -2205,7 +2205,7 @@ def run(self, status: Status | None = None) -> Result: try: cmd = [self._get_juju_binary(), "migrate", self.model, self.to_controller] - LOG.debug(f'Running command {" ".join(cmd)}') + LOG.debug(f"Running command {' '.join(cmd)}") process = subprocess.run(cmd, capture_output=True, text=True, check=True) LOG.debug( f"Command finished. stdout={process.stdout}, stderr={process.stderr}" diff --git a/sunbeam-python/sunbeam/steps/microceph.py b/sunbeam-python/sunbeam/steps/microceph.py index b3a65c0a..b2ce594e 100644 --- a/sunbeam-python/sunbeam/steps/microceph.py +++ b/sunbeam-python/sunbeam/steps/microceph.py @@ -618,7 +618,7 @@ def run(self, status: Status | None = None) -> Result: LOG.debug(f"Failed to remove resource {resource}: {str(e)}") return Result( ResultType.FAILED, - f"Failed to remove resource {resource}" " from state", + f"Failed to remove resource {resource} from state", ) return super().run(status)