~stub/mojo/entry-points

« back to all changes in this revision

Viewing changes to mojo/phase.py

  • Committer: mergebot at canonical
  • Author(s): "Paul Collins"
  • Date: 2020-07-31 07:12:09 UTC
  • mfrom: (566.1.2 fix-reformatting-damage)
  • Revision ID: mergebot@juju-139df4-prod-is-toolbox-0.canonical.com-20200731071209-tp1t7anakhshd5tj
fix pointlessly separated strings

Reviewed-on: https://code.launchpad.net/~pjdc/mojo/fix-reformatting-damage/+merge/388440
Reviewed-by: Tom Haddon <tom.haddon@canonical.com>

Show diffs side-by-side

added added

removed removed

Lines of Context:
112
112
 
113
113
    def run(self, project, workspace, stage=None):
114
114
        "Sleep for time in seconds"
115
 
        logging.debug("### Running phase {} with options {} ###" "".format(self.name, self.options))
 
115
        logging.debug("### Running phase {} with options {} ###".format(self.name, self.options))
116
116
        if self.config_base == "sleep":
117
117
            self.config_base = 30
118
118
        logging.info("Sleeping for {} seconds".format(self.config_base))
120
120
            self.config_base = int(self.config_base)
121
121
        except ValueError:
122
122
            raise NonNumericException(
123
 
                "Time for sleep phase must be the " "numeric number of seconds not '{}'" "".format(self.config_base)
 
123
                "Time for sleep phase must be the numeric number of seconds not '{}'".format(self.config_base)
124
124
            )
125
125
        time.sleep(self.config_base)
126
126
 
163
163
        "Pull Secrets into workspace local"
164
164
 
165
165
        mojo_local_dir = os.path.join(project.mojo_root, "LOCAL", project.name, stage or "devel")
166
 
        logging.debug("### Running phase {} with options {} ###" "".format(self.name, self.options))
167
 
        logging.info("Pulling secrets from {} to {}" "".format(mojo_local_dir, workspace.local_dir))
 
166
        logging.debug("### Running phase {} with options {} ###".format(self.name, self.options))
 
167
        logging.info("Pulling secrets from {} to {}".format(mojo_local_dir, workspace.local_dir))
168
168
        if os.path.isdir(mojo_local_dir):
169
169
            src_files = os.listdir(mojo_local_dir)
170
170
            for file_name in src_files:
183
183
                        shutil.rmtree(dest_dir)
184
184
                    shutil.copytree(full_file_name, os.path.join(workspace.local_dir, file_name))
185
185
                else:
186
 
                    raise FileDoesNotExistException("{} is not a file or " "directory" "".format(full_file_name))
 
186
                    raise FileDoesNotExistException("{} is not a file or directory".format(full_file_name))
187
187
        elif "auto_secrets" in self.options:
188
 
            logging.warn(
189
 
                "Automatic secrets phase ran but secrets " "directory {} does not exist!".format(mojo_local_dir)
190
 
            )
 
188
            logging.warn("Automatic secrets phase ran but secrets directory {} does not exist!".format(mojo_local_dir))
191
189
        else:
192
190
            raise FileDoesNotExistException(
193
191
                "Secrets directory {} does not "
208
206
    def run(self, project, workspace, stage=None, auto_repo=True):
209
207
        "Collect build resources using config-manager"
210
208
        start_time = time.time()
211
 
        logging.debug("### Running phase {} with options {} ###" "".format(self.name, self.options))
 
209
        logging.debug("### Running phase {} with options {} ###".format(self.name, self.options))
212
210
        logging.info("Building resource tree")
213
211
        env = os.environ.copy()
214
212
        env["MOJO_SERIES"] = project.series
280
278
 
281
279
    def run(self, project, workspace, stage=None):
282
280
        "Install packages"
283
 
        logging.debug("### Running phase {} with options {}" "".format(self.name, self.options))
 
281
        logging.debug("### Running phase {} with options {}".format(self.name, self.options))
284
282
        logging.info("Installing apt repos and packages")
285
283
        utils = project.utils
286
284
        repo_keys = self.options.get("repo_keys")
435
433
 
436
434
    def run(self, project, workspace, stage):
437
435
        "Build a charm repository"
438
 
        logging.debug("### Running phase {} with options {}" "".format(self.name, self.options))
 
436
        logging.debug("### Running phase {} with options {}".format(self.name, self.options))
439
437
        logging.info("Build a charm repository")
440
438
        repo = charm_repo.CharmRepo(workspace.repo_dir)
441
439
        if self.options.get("auto_repo"):
442
 
            logging.info("Creating charm repo automatically from all charms " "in the build directory.")
 
440
            logging.info("Creating charm repo automatically from all charms in the build directory.")
443
441
            repo.build_all(workspace.build_dir, project.series)
444
442
        else:
445
443
            logging.warn(
602
600
                    yaml.safe_load(yamlfile)
603
601
            except yaml.parser.ParserError as e:
604
602
                raise InvalidYAMLException(
605
 
                    "Invalid YAML or JSON in " "juju-deployer configuration file " "{}:\n{}".format(config, e)
 
603
                    "Invalid YAML or JSON in juju-deployer configuration file {}:\n{}".format(config, e)
606
604
                )
607
605
            except yaml.scanner.ScannerError as e:
608
606
                raise InvalidYAMLException(
609
 
                    "Invalid YAML or JSON in " "juju-deployer configuration file " "{}:\n{}".format(config, e)
 
607
                    "Invalid YAML or JSON in juju-deployer configuration file {}:\n{}".format(config, e)
610
608
                )
611
609
 
612
610
    def _only_charmstore_charms(self, configs):
675
673
            for config in local_configs:
676
674
                local_cfg_src = os.path.join(workspace.local_dir, config)
677
675
                if not os.path.exists(local_cfg_src):
678
 
                    raise FileDoesNotExistException("Local config file does not exist: " "{}".format(local_cfg_src))
 
676
                    raise FileDoesNotExistException("Local config file does not exist: {}".format(local_cfg_src))
679
677
                local_cfg = os.path.join(workspace.repo_dir, "{}-local.cfg".format(os.path.basename(config)))
680
678
                self.render_config(local_cfg_src, local_cfg, tmpl_vars)
681
679
                configs += (local_cfg,)
783
781
    def run(self, project, workspace, stage, auto_secrets=True):
784
782
        start_time = time.time()
785
783
        self._check_juju_version()
786
 
        logging.debug("### Running phase {} with options {}" "".format(self.name, self.options))
 
784
        logging.debug("### Running phase {} with options {}".format(self.name, self.options))
787
785
        logging.info("Running {} phase".format(self.name))
788
786
 
789
787
        configs = self._get_phase_configs(project, workspace, stage, auto_secrets=auto_secrets)
830
828
        logging.info("Running: {}".format(" ".join(cmd)))
831
829
 
832
830
        if optional:
833
 
            logging.info("NOTE: This phase is marked optional; " "failure will not terminate the run.")
 
831
            logging.info("NOTE: This phase is marked optional; failure will not terminate the run.")
834
832
 
835
833
        with chdir(workspace.repo_dir):
836
834
            status, output = bicommand(" ".join(cmd), showoutput=True, env=env, stderr=subprocess.STDOUT)
839
837
        if status != 0:
840
838
            timeout_fail = re.search("Reached deployment timeout.. exiting", output)
841
839
            if timeout_fail:
842
 
                logging.error(
843
 
                    "Deployment timed out. It was set to {} " "seconds".format(str(self.options.get("timeout")))
844
 
                )
 
840
                logging.error("Deployment timed out. It was set to {} seconds".format(str(self.options.get("timeout"))))
845
841
            if juju.major_version == 1:
846
842
                hook_fail = re.search(".*unit: (?P<unit>[^:]+):.*hook failed", output)
847
843
            elif juju.major_version == 2:
869
865
            juju_status = juju.Status(environment=juju_env)
870
866
            logging.error("Juju Status: {}".format(juju_status.status()))
871
867
            if not timeout_fail and not hook_fail:
872
 
                logging.error("There was an unrecognised problem with " "running a deploy phase")
 
868
                logging.error("There was an unrecognised problem with running a deploy phase")
873
869
 
874
870
            env_vars = ["env"] + ["=".join((k, v)) for k, v in env.items()]
875
871
            self._exec_on_failure(workspace, stage, env_vars)
970
966
    except KeyError:
971
967
        pass
972
968
    except ValueError:
973
 
        logging.warning("Invalid value {} for '{}', " "using {} instead".format(d[k], k, default))
 
969
        logging.warning("Invalid value {} for '{}', using {} instead".format(d[k], k, default))
974
970
 
975
971
    return default
976
972
 
1251
1247
                self._run(project, workspace, stage, services, skip_checks)
1252
1248
            except NagiosCheckPhaseException:
1253
1249
                if i < retry:
1254
 
                    logging.warning(
1255
 
                        "nagios-check failed (attempt {} of {}); " "sleeping for {}s".format(i, retry, sleep)
1256
 
                    )
 
1250
                    logging.warning("nagios-check failed (attempt {} of {}); sleeping for {}s".format(i, retry, sleep))
1257
1251
                    time.sleep(sleep)
1258
1252
                else:
1259
1253
                    raise
1446
1440
    if getattr(phase_types, "cache", None) is None:
1447
1441
        phase_types.cache = phase_types(Phase)
1448
1442
    if phase_name not in phase_types.cache:
1449
 
        raise NoSuchPhaseError("{} is not a registered phase type" "".format(phase_name))
 
1443
        raise NoSuchPhaseError("{} is not a registered phase type".format(phase_name))
1450
1444
    return phase_types.cache[phase_name](**kwargs)
1451
1445
 
1452
1446