def deactivate_bootloader(self, context, node, instance): """Delete PXE bootloader images and config.""" try: db.bm_node_update( context, node["id"], {"deploy_key": None, "image_path": None, "pxe_config_path": None, "root_mb": 0, "swap_mb": 0}, ) except exception.NodeNotFound: pass # NOTE(danms): the flavor extra_specs do not need to be # present/correct at deactivate time, so pass something empty # to avoid an extra lookup flavor = dict(extra_specs={"baremetal:deploy_ramdisk_id": "ignore", "baremetal:deploy_kernel_id": "ignore"}) try: image_info = get_tftp_image_info(instance, flavor) except exception.NovaException: pass else: for label in image_info.keys(): (uuid, path) = image_info[label] bm_utils.unlink_without_raise(path) bm_utils.unlink_without_raise(get_pxe_config_file_path(instance)) try: macs = self._collect_mac_addresses(context, node) except db_exc.DBError: pass else: for mac in macs: bm_utils.unlink_without_raise(get_pxe_mac_path(mac)) bm_utils.rmtree_without_raise(os.path.join(CONF.baremetal.tftp_root, instance["uuid"]))
def deactivate_bootloader(self, context, node, instance): """Delete Tilera bootloader images and config.""" try: db.bm_node_update( context, node["id"], {"deploy_key": None, "image_path": None, "pxe_config_path": None, "root_mb": 0, "swap_mb": 0}, ) except exception.NodeNotFound: pass tilera_nfs_path = get_tilera_nfs_path(node["id"]) if os.path.ismount(tilera_nfs_path): utils.execute("rpc.mountd", run_as_root=True) utils.execute("umount", "-f", tilera_nfs_path, run_as_root=True) try: image_info = get_tftp_image_info(instance) except exception.NovaException: pass else: for label in image_info.keys(): (uuid, path) = image_info[label] bm_utils.unlink_without_raise(path) try: self._collect_mac_addresses(context, node) except db_exc.DBError: pass if os.path.exists(os.path.join(CONF.baremetal.tftp_root, instance["uuid"])): bm_utils.rmtree_without_raise(os.path.join(CONF.baremetal.tftp_root, instance["uuid"]))
def test_deactivate_bootloader(self): self._create_node() macs = [nic['address'] for nic in self.nic_info] macs.append(self.node_info['prov_mac_address']) macs.sort() image_info = { 'deploy_kernel': [None, 'aaaa'], 'deploy_ramdisk': [None, 'bbbb'], 'kernel': [None, 'cccc'], 'ramdisk': [None, 'dddd'], } self.instance['uuid'] = 'fake-uuid' pxe_path = pxe.get_pxe_config_file_path(self.instance) self.mox.StubOutWithMock(bm_utils, 'unlink_without_raise') self.mox.StubOutWithMock(bm_utils, 'rmtree_without_raise') self.mox.StubOutWithMock(pxe, 'get_tftp_image_info') self.mox.StubOutWithMock(self.driver, '_collect_mac_addresses') pxe.get_tftp_image_info(self.instance).AndReturn(image_info) for uuid, path in [image_info[label] for label in image_info]: bm_utils.unlink_without_raise(path) bm_utils.unlink_without_raise(pxe_path) self.driver._collect_mac_addresses(self.context, self.node).\ AndReturn(macs) for mac in macs: bm_utils.unlink_without_raise(pxe.get_pxe_mac_path(mac)) bm_utils.rmtree_without_raise( os.path.join(CONF.baremetal.tftp_root, 'fake-uuid')) self.mox.ReplayAll() self.driver.deactivate_bootloader( self.context, self.node, self.instance) self.mox.VerifyAll()
def test_deactivate_bootloader_for_nonexistent_instance(self): self._create_node() macs = [nic['address'] for nic in self.nic_info] macs.append(self.node_info['prov_mac_address']) macs.sort() image_info = { 'deploy_kernel': [None, 'aaaa'], 'deploy_ramdisk': [None, 'bbbb'], 'kernel': [None, 'cccc'], 'ramdisk': [None, 'dddd'], } self.instance['uuid'] = 'fake-uuid' pxe_path = pxe.get_pxe_config_file_path(self.instance) self.mox.StubOutWithMock(bm_utils, 'unlink_without_raise') self.mox.StubOutWithMock(bm_utils, 'rmtree_without_raise') self.mox.StubOutWithMock(pxe, 'get_tftp_image_info') self.mox.StubOutWithMock(self.driver, '_collect_mac_addresses') pxe.get_tftp_image_info(self.instance).\ AndRaise(exception.NovaException) bm_utils.unlink_without_raise(pxe_path) self.driver._collect_mac_addresses(self.context, self.node).\ AndRaise(db_session.DBError) bm_utils.rmtree_without_raise( os.path.join(CONF.baremetal.tftp_root, 'fake-uuid')) self.mox.ReplayAll() self.driver.deactivate_bootloader( self.context, self.node, self.instance) self.mox.VerifyAll()
def test_deactivate_bootloader_for_nonexistent_instance(self): self._create_node() self.instance['uuid'] = 'fake-uuid' pxe_path = pxe.get_pxe_config_file_path(self.instance) self.mox.StubOutWithMock(bm_utils, 'unlink_without_raise') self.mox.StubOutWithMock(bm_utils, 'rmtree_without_raise') self.mox.StubOutWithMock(pxe, 'get_tftp_image_info') self.mox.StubOutWithMock(self.driver, '_collect_mac_addresses') extra_specs = dict( extra_specs={ 'baremetal:deploy_ramdisk_id': 'ignore', 'baremetal:deploy_kernel_id': 'ignore' }) pxe.get_tftp_image_info(self.instance, extra_specs).\ AndRaise(exception.NovaException) bm_utils.unlink_without_raise(pxe_path) self.driver._collect_mac_addresses(self.context, self.node).\ AndRaise(db_exc.DBError) bm_utils.rmtree_without_raise( os.path.join(CONF.baremetal.tftp_root, 'fake-uuid')) self.mox.ReplayAll() self.driver.deactivate_bootloader(self.context, self.node, self.instance) self.mox.VerifyAll()
def test_deactivate_bootloader_for_nonexistent_instance(self): self._create_node() self.instance['uuid'] = 'fake-uuid' pxe_path = pxe.get_pxe_config_file_path(self.instance) self.mox.StubOutWithMock(bm_utils, 'unlink_without_raise') self.mox.StubOutWithMock(bm_utils, 'rmtree_without_raise') self.mox.StubOutWithMock(pxe, 'get_tftp_image_info') self.mox.StubOutWithMock(self.driver, '_collect_mac_addresses') extra_specs = dict(extra_specs={ 'baremetal:deploy_ramdisk_id': 'ignore', 'baremetal:deploy_kernel_id': 'ignore'}) pxe.get_tftp_image_info(self.instance, extra_specs).\ AndRaise(exception.NovaException) bm_utils.unlink_without_raise(pxe_path) self.driver._collect_mac_addresses(self.context, self.node).\ AndRaise(db_exc.DBError) bm_utils.rmtree_without_raise( os.path.join(CONF.baremetal.tftp_root, 'fake-uuid')) self.mox.ReplayAll() self.driver.deactivate_bootloader( self.context, self.node, self.instance) self.mox.VerifyAll()
def test_deactivate_bootloader_for_nonexistent_instance(self): self._create_node() macs = [nic['address'] for nic in self.nic_info] macs.append(self.node_info['prov_mac_address']) macs.sort() image_info = { 'deploy_kernel': [None, 'aaaa'], 'deploy_ramdisk': [None, 'bbbb'], 'kernel': [None, 'cccc'], 'ramdisk': [None, 'dddd'], } self.instance['uuid'] = 'fake-uuid' pxe_path = pxe.get_pxe_config_file_path(self.instance) self.mox.StubOutWithMock(bm_utils, 'unlink_without_raise') self.mox.StubOutWithMock(bm_utils, 'rmtree_without_raise') self.mox.StubOutWithMock(pxe, 'get_tftp_image_info') self.mox.StubOutWithMock(self.driver, '_collect_mac_addresses') pxe.get_tftp_image_info(self.instance).\ AndRaise(exception.NovaException) bm_utils.unlink_without_raise(pxe_path) self.driver._collect_mac_addresses(self.context, self.node).\ AndRaise(exception.DBError) bm_utils.rmtree_without_raise( os.path.join(CONF.baremetal.tftp_root, 'fake-uuid')) self.mox.ReplayAll() self.driver.deactivate_bootloader( self.context, self.node, self.instance) self.mox.VerifyAll()
def deactivate_bootloader(self, context, node, instance): """Delete PXE bootloader images and config.""" try: db.bm_node_update(context, node['id'], {'deploy_key': None, 'image_path': None, 'pxe_config_path': None, 'root_mb': 0, 'swap_mb': 0}) except exception.NodeNotFound: pass try: image_info = get_tftp_image_info(instance) except exception.NovaException: pass else: for label in image_info.keys(): (uuid, path) = image_info[label] bm_utils.unlink_without_raise(path) bm_utils.unlink_without_raise(get_pxe_config_file_path(instance)) try: macs = self._collect_mac_addresses(context, node) except db_session.DBError: pass else: for mac in macs: bm_utils.unlink_without_raise(get_pxe_mac_path(mac)) bm_utils.rmtree_without_raise( os.path.join(CONF.baremetal.tftp_root, instance['uuid']))
def test_activate_and_deactivate_bootloader(self): self._create_node() instance_type = { 'extra_specs': { 'baremetal:deploy_kernel_id': 'eeee', 'baremetal:deploy_ramdisk_id': 'ffff', } } self.instance['uuid'] = 'fake-uuid' self.mox.StubOutWithMock(self.driver.virtapi, 'instance_type_get') self.mox.StubOutWithMock(bm_utils, 'write_to_file') self.mox.StubOutWithMock(bm_utils, 'create_link_without_raise') self.mox.StubOutWithMock(bm_utils, 'unlink_without_raise') self.mox.StubOutWithMock(bm_utils, 'rmtree_without_raise') self.driver.virtapi.instance_type_get( self.context, self.instance['instance_type_id']).AndReturn(instance_type) # create the config file bm_utils.write_to_file(mox.StrContains('fake-uuid'), mox.StrContains(CONF.baremetal.tftp_root)) # unlink and link the 2 interfaces for i in range(2): bm_utils.unlink_without_raise( mox.Or(mox.StrContains('fake-uuid'), mox.StrContains(CONF.baremetal.tftp_root))) bm_utils.create_link_without_raise( mox.StrContains('fake-uuid'), mox.StrContains(CONF.baremetal.tftp_root)) # unlink all 2 interfaces, 4 images, and the config file for i in range(7): bm_utils.unlink_without_raise( mox.Or(mox.StrContains('fake-uuid'), mox.StrContains(CONF.baremetal.tftp_root))) bm_utils.rmtree_without_raise(mox.StrContains('fake-uuid')) self.mox.ReplayAll() # activate and deactivate the bootloader # and check the deployment task_state in the database row = db.bm_node_get(self.context, 1) self.assertIsNone(row['deploy_key']) self.driver.activate_bootloader(self.context, self.node, self.instance, network_info=self.test_network_info) row = db.bm_node_get(self.context, 1) self.assertIsNotNone(row['deploy_key']) self.driver.deactivate_bootloader(self.context, self.node, self.instance) row = db.bm_node_get(self.context, 1) self.assertIsNone(row['deploy_key']) self.mox.VerifyAll()
def test_activate_and_deactivate_bootloader(self): self._create_node() flavor = { 'extra_specs': { 'baremetal:deploy_kernel_id': 'eeee', 'baremetal:deploy_ramdisk_id': 'ffff', } } self.instance['uuid'] = 'fake-uuid' self.mox.StubOutWithMock(self.driver.virtapi, 'flavor_get') self.mox.StubOutWithMock(bm_utils, 'write_to_file') self.mox.StubOutWithMock(bm_utils, 'create_link_without_raise') self.mox.StubOutWithMock(bm_utils, 'unlink_without_raise') self.mox.StubOutWithMock(bm_utils, 'rmtree_without_raise') self.driver.virtapi.flavor_get( self.context, self.instance['instance_type_id']).AndReturn( flavor) # create the config file bm_utils.write_to_file(mox.StrContains('fake-uuid'), mox.StrContains(CONF.baremetal.tftp_root)) # unlink and link the 2 interfaces for i in range(2): bm_utils.unlink_without_raise(mox.Or( mox.StrContains('fake-uuid'), mox.StrContains(CONF.baremetal.tftp_root))) bm_utils.create_link_without_raise( mox.StrContains('fake-uuid'), mox.StrContains(CONF.baremetal.tftp_root)) # unlink all 2 interfaces, 4 images, and the config file for i in range(7): bm_utils.unlink_without_raise(mox.Or( mox.StrContains('fake-uuid'), mox.StrContains(CONF.baremetal.tftp_root))) bm_utils.rmtree_without_raise(mox.StrContains('fake-uuid')) self.mox.ReplayAll() # activate and deactivate the bootloader # and check the deployment task_state in the database row = db.bm_node_get(self.context, 1) self.assertIsNone(row['deploy_key']) self.driver.activate_bootloader(self.context, self.node, self.instance, network_info=self.test_network_info) row = db.bm_node_get(self.context, 1) self.assertIsNotNone(row['deploy_key']) self.driver.deactivate_bootloader(self.context, self.node, self.instance) row = db.bm_node_get(self.context, 1) self.assertIsNone(row['deploy_key']) self.mox.VerifyAll()
def test_destroy_images(self): self._create_node() self.mox.StubOutWithMock(bm_utils, 'unlink_without_raise') self.mox.StubOutWithMock(bm_utils, 'rmtree_without_raise') bm_utils.unlink_without_raise(pxe.get_image_file_path(self.instance)) bm_utils.rmtree_without_raise(pxe.get_image_dir_path(self.instance)) self.mox.ReplayAll() self.driver.destroy_images(self.context, self.node, self.instance) self.mox.VerifyAll()
def test_activate_and_deactivate_bootloader(self): self._create_node() extra_specs = { 'deploy_kernel_id': 'eeee', 'deploy_ramdisk_id': 'ffff', } self.instance['extra_specs'] = extra_specs self.instance['uuid'] = 'fake-uuid' self.mox.StubOutWithMock(bm_utils, 'write_to_file') self.mox.StubOutWithMock(bm_utils, 'create_link_without_raise') self.mox.StubOutWithMock(bm_utils, 'unlink_without_raise') self.mox.StubOutWithMock(bm_utils, 'rmtree_without_raise') # create the config file bm_utils.write_to_file(mox.StrContains('fake-uuid'), mox.StrContains(CONF.baremetal.tftp_root)) # unlink and link the 3 interfaces for i in range(3): bm_utils.unlink_without_raise(mox.Or( mox.StrContains('fake-uuid'), mox.StrContains(CONF.baremetal.tftp_root))) bm_utils.create_link_without_raise( mox.StrContains('fake-uuid'), mox.StrContains(CONF.baremetal.tftp_root)) # unlink all 3 interfaces, 4 images, and the config file for i in range(8): bm_utils.unlink_without_raise(mox.Or( mox.StrContains('fake-uuid'), mox.StrContains(CONF.baremetal.tftp_root))) bm_utils.rmtree_without_raise(mox.StrContains('fake-uuid')) self.mox.ReplayAll() # activate and deactivate the bootloader # and check the deployment task_state in the database row = db.bm_node_get(self.context, 1) self.assertTrue(row['deploy_key'] is None) self.driver.activate_bootloader(self.context, self.node, self.instance) row = db.bm_node_get(self.context, 1) self.assertTrue(row['deploy_key'] is not None) self.driver.deactivate_bootloader(self.context, self.node, self.instance) row = db.bm_node_get(self.context, 1) self.assertTrue(row['deploy_key'] is None) self.mox.VerifyAll()
def test_activate_and_deactivate_bootloader(self): self._create_node() flavor = objects.Flavor( context=self.context, extra_specs={"baremetal:deploy_kernel_id": "eeee", "baremetal:deploy_ramdisk_id": "ffff"}, ) self.instance["uuid"] = "fake-uuid" self.mox.StubOutWithMock(objects.Flavor, "get_by_id") self.mox.StubOutWithMock(bm_utils, "write_to_file") self.mox.StubOutWithMock(bm_utils, "create_link_without_raise") self.mox.StubOutWithMock(bm_utils, "unlink_without_raise") self.mox.StubOutWithMock(bm_utils, "rmtree_without_raise") objects.Flavor.get_by_id(self.context, self.instance["instance_type_id"]).AndReturn(flavor) # create the config file bm_utils.write_to_file(mox.StrContains("fake-uuid"), mox.StrContains(CONF.baremetal.tftp_root)) # unlink and link the 2 interfaces for i in range(2): bm_utils.unlink_without_raise( mox.Or(mox.StrContains("fake-uuid"), mox.StrContains(CONF.baremetal.tftp_root)) ) bm_utils.create_link_without_raise(mox.StrContains("fake-uuid"), mox.StrContains(CONF.baremetal.tftp_root)) # unlink all 2 interfaces, 4 images, and the config file for i in range(7): bm_utils.unlink_without_raise( mox.Or(mox.StrContains("fake-uuid"), mox.StrContains(CONF.baremetal.tftp_root)) ) bm_utils.rmtree_without_raise(mox.StrContains("fake-uuid")) self.mox.ReplayAll() # activate and deactivate the bootloader # and check the deployment task_state in the database row = db.bm_node_get(self.context, 1) self.assertIsNone(row["deploy_key"]) self.driver.activate_bootloader(self.context, self.node, self.instance, network_info=self.test_network_info) row = db.bm_node_get(self.context, 1) self.assertIsNotNone(row["deploy_key"]) self.driver.deactivate_bootloader(self.context, self.node, self.instance) row = db.bm_node_get(self.context, 1) self.assertIsNone(row["deploy_key"]) self.mox.VerifyAll()
def test_activate_and_deactivate_bootloader(self): self._create_node() instance_type = {"extra_specs": {"baremetal:deploy_kernel_id": "eeee", "baremetal:deploy_ramdisk_id": "ffff"}} self.instance["uuid"] = "fake-uuid" self.mox.StubOutWithMock(self.driver.virtapi, "instance_type_get") self.mox.StubOutWithMock(bm_utils, "write_to_file") self.mox.StubOutWithMock(bm_utils, "create_link_without_raise") self.mox.StubOutWithMock(bm_utils, "unlink_without_raise") self.mox.StubOutWithMock(bm_utils, "rmtree_without_raise") self.driver.virtapi.instance_type_get(self.context, self.instance["instance_type_id"]).AndReturn(instance_type) # create the config file bm_utils.write_to_file(mox.StrContains("fake-uuid"), mox.StrContains(CONF.baremetal.tftp_root)) # unlink and link the 3 interfaces for i in range(3): bm_utils.unlink_without_raise( mox.Or(mox.StrContains("fake-uuid"), mox.StrContains(CONF.baremetal.tftp_root)) ) bm_utils.create_link_without_raise(mox.StrContains("fake-uuid"), mox.StrContains(CONF.baremetal.tftp_root)) # unlink all 3 interfaces, 4 images, and the config file for i in range(8): bm_utils.unlink_without_raise( mox.Or(mox.StrContains("fake-uuid"), mox.StrContains(CONF.baremetal.tftp_root)) ) bm_utils.rmtree_without_raise(mox.StrContains("fake-uuid")) self.mox.ReplayAll() # activate and deactivate the bootloader # and check the deployment task_state in the database row = db.bm_node_get(self.context, 1) self.assertTrue(row["deploy_key"] is None) self.driver.activate_bootloader(self.context, self.node, self.instance) row = db.bm_node_get(self.context, 1) self.assertTrue(row["deploy_key"] is not None) self.driver.deactivate_bootloader(self.context, self.node, self.instance) row = db.bm_node_get(self.context, 1) self.assertTrue(row["deploy_key"] is None) self.mox.VerifyAll()
def test_deactivate_bootloader_for_nonexistent_instance(self): self._create_node() self.instance["uuid"] = "fake-uuid" pxe_path = pxe.get_pxe_config_file_path(self.instance) self.mox.StubOutWithMock(bm_utils, "unlink_without_raise") self.mox.StubOutWithMock(bm_utils, "rmtree_without_raise") self.mox.StubOutWithMock(pxe, "get_tftp_image_info") self.mox.StubOutWithMock(self.driver, "_collect_mac_addresses") extra_specs = dict(extra_specs=dict(deploy_ramdisk_id="ignore", deploy_kernel_id="ignore")) pxe.get_tftp_image_info(self.instance, extra_specs).AndRaise(exception.NovaException) bm_utils.unlink_without_raise(pxe_path) self.driver._collect_mac_addresses(self.context, self.node).AndRaise(db_exc.DBError) bm_utils.rmtree_without_raise(os.path.join(CONF.baremetal.tftp_root, "fake-uuid")) self.mox.ReplayAll() self.driver.deactivate_bootloader(self.context, self.node, self.instance) self.mox.VerifyAll()
def deactivate_bootloader(self, context, node, instance): """Delete PXE bootloader images and config.""" try: db.bm_node_update( context, node['id'], { 'deploy_key': None, 'image_path': None, 'pxe_config_path': None, 'root_mb': 0, 'swap_mb': 0 }) except exception.NodeNotFound: pass # NOTE(danms): the instance_type extra_specs do not need to be # present/correct at deactivate time, so pass something empty # to avoid an extra lookup instance_type = dict( extra_specs={ 'baremetal:deploy_ramdisk_id': 'ignore', 'baremetal:deploy_kernel_id': 'ignore' }) try: image_info = get_tftp_image_info(instance, instance_type) except exception.NovaException: pass else: for label in image_info.keys(): (uuid, path) = image_info[label] bm_utils.unlink_without_raise(path) bm_utils.unlink_without_raise(get_pxe_config_file_path(instance)) try: macs = self._collect_mac_addresses(context, node) except db_exc.DBError: pass else: for mac in macs: bm_utils.unlink_without_raise(get_pxe_mac_path(mac)) bm_utils.rmtree_without_raise( os.path.join(CONF.baremetal.tftp_root, instance['uuid']))
def deactivate_bootloader(self, context, node, instance): """Delete PXE bootloader images and config.""" try: image_info = get_tftp_image_info(instance) except exception.NovaException: pass else: for label in image_info.keys(): (uuid, path) = image_info[label] bm_utils.unlink_without_raise(path) bm_utils.unlink_without_raise(get_pxe_config_file_path(instance)) try: macs = self._collect_mac_addresses(context, node) except exception.DBError: pass else: for mac in macs: bm_utils.unlink_without_raise(get_pxe_mac_path(mac)) bm_utils.rmtree_without_raise(os.path.join(CONF.baremetal.tftp_root, instance["uuid"]))
def deactivate_bootloader(self, context, node, instance): """Delete PXE bootloader images and config.""" try: image_info = get_tftp_image_info(instance) except exception.NovaException: pass else: for label in image_info.keys(): (uuid, path) = image_info[label] bm_utils.unlink_without_raise(path) bm_utils.unlink_without_raise(get_pxe_config_file_path(instance)) try: macs = self._collect_mac_addresses(context, node) except exception.DBError: pass else: for mac in macs: bm_utils.unlink_without_raise(get_pxe_mac_path(mac)) bm_utils.rmtree_without_raise( os.path.join(CONF.baremetal.tftp_root, instance['uuid']))
def deactivate_bootloader(self, context, node, instance): """Delete Tilera bootloader images and config.""" try: db.bm_node_update( context, node['id'], { 'deploy_key': None, 'image_path': None, 'pxe_config_path': None, 'root_mb': 0, 'swap_mb': 0 }) except exception.NodeNotFound: pass tilera_nfs_path = get_tilera_nfs_path(node['id']) if os.path.ismount(tilera_nfs_path): utils.execute('rpc.mountd', run_as_root=True) utils.execute('umount', '-f', tilera_nfs_path, run_as_root=True) try: image_info = get_tftp_image_info(instance) except exception.NovaException: pass else: for label in image_info.keys(): (uuid, path) = image_info[label] bm_utils.unlink_without_raise(path) try: self._collect_mac_addresses(context, node) except db_exc.DBError: pass if os.path.exists( os.path.join(CONF.baremetal.tftp_root, instance['uuid'])): bm_utils.rmtree_without_raise( os.path.join(CONF.baremetal.tftp_root, instance['uuid']))
def destroy_images(self, context, node, instance): """Delete instance's image file.""" bm_utils.unlink_without_raise(get_image_file_path(instance)) bm_utils.rmtree_without_raise(get_image_dir_path(instance))