def execute(self): """Execute command.""" msg_src = self.__class__.__name__ LOG.debug(f'{msg_src}: Execute: Target:' f' {self.cmd_opts.get(CLI_CMDOPT.CMD_TARGET)}') if self.cmd_opts.get(CLI_CMDOPT.CMD_TARGET) == CLI_CMDTARGET.STORAGE: # (Re)build/repair the installation storage structure. self.config.inst_storage.construct( clean=self.cmd_opts.get(CLI_CMDOPT.INST_CLEAN)) elif self.cmd_opts.get(CLI_CMDOPT.CMD_TARGET) == CLI_CMDTARGET.PKGALL: dstor_root_url = self.config.cluster_conf.get( 'distribution-storage', {}).get('rooturl', '') dstor_pkgrepo_path = self.config.cluster_conf.get( 'distribution-storage', {}).get('pkgrepopath', '') # Add packages to the local package repository and initialize their # manager objects packages_bulk = [] for item in self.config.ref_pkg_list: pkg_id = PackageId(pkg_id=item) try: self.config.inst_storage.add_package( pkg_id=pkg_id, dstor_root_url=dstor_root_url, dstor_pkgrepo_path=dstor_pkgrepo_path) except cr_exc.RCError as e: err_msg = (f'{msg_src}: Execute: Add package to local' f' repository: {pkg_id.pkg_id}: {e}') raise cr_exc.SetupCommandError(err_msg) from e try: package = Package( pkg_id=pkg_id, istor_nodes=self.config.inst_storage.istor_nodes, cluster_conf=self.config.cluster_conf) except cr_exc.RCError as e: err_msg = (f'{msg_src}: Execute: Initialize package:' f' {pkg_id.pkg_id}: {e}') raise cr_exc.SetupCommandError(err_msg) from e packages_bulk.append(package) # Finalize package setup procedures taking package mutual # dependencies into account. for package in cr_utl.pkg_sort_by_deps(packages_bulk): self._handle_pkg_inst_extras(package) self._handle_pkg_svc_setup(package) try: package.manifest.save() except cr_exc.RCError as e: err_msg = (f'{msg_src}: Execute: Register package:' f' {package.manifest.pkg_id.pkg_id}: {e}') raise cr_exc.SetupCommandError(err_msg) LOG.info(f'{msg_src}: Setup package:' f' {package.manifest.pkg_id.pkg_id}: OK')
def execute(self): """Execute command.""" LOG.debug(f'{self.msg_src}: Execute: Target:' f' {self.cmd_opts.get(CLI_CMDOPT.CMD_TARGET)}') if self.cmd_opts.get(CLI_CMDOPT.CMD_TARGET) == CLI_CMDTARGET.STORAGE: # (Re)build/repair the installation storage structure. self.config.inst_storage.construct( clean=self.cmd_opts.get(CLI_CMDOPT.INST_CLEAN)) elif self.cmd_opts.get(CLI_CMDOPT.CMD_TARGET) == CLI_CMDTARGET.PKGALL: dstor_root_url = self.config.cluster_conf.get( 'distribution-storage', {}).get('rooturl', '') dstor_pkgrepo_path = self.config.cluster_conf.get( 'distribution-storage', {}).get('pkgrepopath', '') # Add packages to the local package repository and initialize their # manager objects packages_bulk = {} for item in self.config.ref_pkg_list: pkg_id = PackageId(pkg_id=item) try: self.config.inst_storage.add_package( pkg_id=pkg_id, dstor_root_url=dstor_root_url, dstor_pkgrepo_path=dstor_pkgrepo_path) except cr_exc.RCError as e: err_msg = (f'{self.msg_src}: Execute: Add package to local' f' repository: {pkg_id.pkg_id}: {e}') raise cr_exc.SetupCommandError(err_msg) from e try: package = Package( pkg_id=pkg_id, istor_nodes=self.config.inst_storage.istor_nodes, cluster_conf=self.config.cluster_conf, extra_context=self.config.dcos_conf.get('values')) except cr_exc.RCError as e: err_msg = (f'{self.msg_src}: Execute: Initialize package:' f' {pkg_id.pkg_id}: {e}') raise cr_exc.SetupCommandError(err_msg) from e packages_bulk[pkg_id.pkg_name] = package # Finalize package setup procedures taking package mutual # dependencies into account. packages_sorted_by_deps = cr_utl.pkg_sort_by_deps(packages_bulk) # Prepare base per package configuration objects for package in packages_sorted_by_deps: self._handle_pkg_dir_setup(package) self._handle_pkg_cfg_setup(package) # Deploy DC/OS aggregated configuration object self._deploy_dcos_conf() # Run per package extra installation helpers, setup services and # save manifests for package in packages_sorted_by_deps: self._handle_pkg_inst_extras(package) self._handle_pkg_svc_setup(package) try: package.manifest.save() except cr_exc.RCError as e: err_msg = (f'{self.msg_src}: Execute: Register package:' f' {package.manifest.pkg_id.pkg_id}: {e}') raise cr_exc.SetupCommandError(err_msg) LOG.info(f'{self.msg_src}: Setup package:' f' {package.manifest.pkg_id.pkg_id}: OK')
def _handle_clean_setup(self): """Perform all the steps on DC/OS installation remaining after the preparation stage is done (the CmdUpgrade._handle_upgrade_pre()). """ # TODO: This code duplicates the CmdSetup._handle_cmdtarget_pkgall() # stuff and so should be made standalone to be reused in both # classes avoiding massive code duplication. dstor_root_url = self.config.cluster_conf.get('distribution-storage', {}).get('rooturl', '') dstor_pkgrepo_path = self.config.cluster_conf.get( 'distribution-storage', {}).get('pkgrepopath', '') # Deploy DC/OS aggregated configuration object self._deploy_dcos_conf() result = subprocess.run( ('powershell', '-executionpolicy', 'Bypass', '-File', 'C:\\d2iq\\dcos\\bin\\detect_ip.ps1'), stdout=subprocess.PIPE, check=True) local_priv_ipaddr = result.stdout.decode('ascii').strip() self.config.dcos_conf['values']['privateipaddr'] = local_priv_ipaddr # Add packages to the local package repository and initialize their # manager objects packages_bulk = {} for item in self.config.ref_pkg_list: pkg_id = PackageId(pkg_id=item) try: self.config.inst_storage.add_package( pkg_id=pkg_id, dstor_root_url=dstor_root_url, dstor_pkgrepo_path=dstor_pkgrepo_path) except cr_exc.RCError as e: err_msg = (f'{self.msg_src}: Execute: Add package to local' f' repository: {pkg_id.pkg_id}: {e}') raise cr_exc.SetupCommandError(err_msg) from e try: package = Package( pkg_id=pkg_id, istor_nodes=self.config.inst_storage.istor_nodes, cluster_conf=self.config.cluster_conf, extra_context=self.config.dcos_conf.get('values')) except cr_exc.RCError as e: err_msg = (f'{self.msg_src}: Execute: Initialize package:' f' {pkg_id.pkg_id}: {e}') raise cr_exc.SetupCommandError(err_msg) from e packages_bulk[pkg_id.pkg_name] = package # Finalize package setup procedures taking package mutual # dependencies into account. packages_sorted_by_deps = cr_utl.pkg_sort_by_deps(packages_bulk) # Prepare base per package configuration objects for package in packages_sorted_by_deps: # TODO: This method moves parts of individual packages which should # be shared with other packages to DC/OS installation shared # directories (<inst_root>\[bin|etc|lib]). It should be # redesigned to deal with only required parts of packages and # not populating shared DC/OS installation directories with # unnecessary stuff. self._handle_pkg_dir_setup(package) # TODO: This should be replaced with Package.handle_config_setup() # method to avoid code duplication in command manager classes # CmdSetup and CmdUpgrade self._handle_pkg_cfg_setup(package) # Run per package extra installation helpers, setup services and # save manifests for package in packages_sorted_by_deps: # TODO: This should be replaced with Package.handle_inst_extras() # method to avoid code duplication in command manager classes # CmdSetup and CmdUpgrade self._handle_pkg_inst_extras(package) # TODO: This should be replaced with Package.handle_svc_setup() # method to avoid code duplication in command manager classes # CmdSetup and CmdUpgrade self._handle_pkg_svc_setup(package) # TODO: This part should be replaced with Package.save_manifest() # method to avoid code duplication in command manager classes # CmdSetup and CmdUpgrade try: package.manifest.save() except cr_exc.RCError as e: err_msg = (f'{self.msg_src}: Execute: Register package:' f' {package.manifest.pkg_id.pkg_id}: {e}') raise cr_exc.SetupCommandError(err_msg) LOG.info(f'{self.msg_src}: Setup package:' f' {package.manifest.pkg_id.pkg_id}: OK')
def test_manifest_should_not_be_changed_in_init(self, *args): """Check Package constructor manifest processing.""" manifest = mock.Mock(spec=PackageManifest) manifest.pkg_svccfg = {} pack = Package(PackageId(), manifest=manifest) assert pack.manifest == manifest
def test_package_id_should_be_same_as_in_package(self, *args): """Check PackageManifest constructor package_id processing.""" pkg = PackageId('id--ver') manifest = PackageManifest(pkg, mock.Mock(spec=IStorNodes), {}) assert str(manifest.pkg_id) == pkg.pkg_id
def test_name_and_version_should_create_id(self): """Check PackageId constructor pkg_name and pkg_version processing.""" pkg = PackageId(pkg_name='id', pkg_version='ver') assert str(pkg) == 'id--ver'
def test_wrong_id_should_fail(self): """Check PackageId wrong id value exception handling.""" with pytest.raises(ValueError): PackageId('id')
def test_str_method_should_return_id_string(self): """Check PackageId __str__ magic method return value.""" name = 'id--ver' pkg = PackageId(name) assert str(pkg) == name