def test_migrate_disk_and_power_off(self): instance_ref, network_info = self._get_running_instance() instance_type_ref = test_utils.get_test_instance_type() self.connection.migrate_disk_and_power_off(self.ctxt, instance_ref, 'dest_host', instance_type_ref, network_info)
def test_swap_not_zero(self): # override swap to 0 instance_type = utils.get_test_instance_type(self.context) instance_type['swap'] = 0 self.instance = utils.get_test_instance(self.context, instance_type) sizes = tilera.get_partition_sizes(self.instance) self.assertEqual(sizes[0], 40960) self.assertEqual(sizes[1], 1)
def _create_node(self, node_info=None, nic_info=None, ephemeral=True): result = {} if node_info is None: node_info = bm_db_utils.new_bm_node( id=123, service_host='test_host', cpus=2, memory_mb=2048, ) if nic_info is None: nic_info = [ { 'address': '01:23:45:67:89:01', 'datapath_id': '0x1', 'port_no': 1 }, { 'address': '01:23:45:67:89:02', 'datapath_id': '0x2', 'port_no': 2 }, ] result['node_info'] = node_info result['nic_info'] = nic_info result['node'] = db.bm_node_create(self.context, node_info) for nic in nic_info: db.bm_interface_create( self.context, result['node']['id'], nic['address'], nic['datapath_id'], nic['port_no'], ) if ephemeral: result['instance'] = utils.get_test_instance() else: flavor = utils.get_test_instance_type(options={'ephemeral_gb': 0}) result['instance'] = utils.get_test_instance(instance_type=flavor) result['instance']['node'] = result['node']['uuid'] result['spawn_params'] = dict( admin_password='******', block_device_info=None, context=self.context, image_meta=utils.get_test_image_info(None, result['instance']), injected_files=[('/fake/path', 'hello world')], instance=result['instance'], network_info=utils.get_test_network_info(), ) result['destroy_params'] = dict( context=self.context, instance=result['instance'], network_info=result['spawn_params']['network_info'], block_device_info=result['spawn_params']['block_device_info'], ) return result
def test_swap_not_zero(self): # override swap to 0 flavor = utils.get_test_instance_type(self.context) flavor['swap'] = 0 self.instance = utils.get_test_instance(self.context, flavor) sizes = pxe.get_partition_sizes(self.instance) self.assertEqual(sizes[0], 40960) self.assertEqual(sizes[1], 1)
def test_get_tftp_image_info(self): instance_type = utils.get_test_instance_type() # Raises an exception when options are neither specified # on the instance nor in configuration file CONF.baremetal.deploy_kernel = None CONF.baremetal.deploy_ramdisk = None self.assertRaises(exception.NovaException, pxe.get_tftp_image_info, self.instance, instance_type) # Test that other non-true values also raise an exception CONF.baremetal.deploy_kernel = "" CONF.baremetal.deploy_ramdisk = "" self.assertRaises(exception.NovaException, pxe.get_tftp_image_info, self.instance, instance_type) # Even if the instance includes kernel_id and ramdisk_id, # we still need deploy_kernel_id and deploy_ramdisk_id. # If those aren't present in instance[], and not specified in # config file, then we raise an exception. self.instance["kernel_id"] = "aaaa" self.instance["ramdisk_id"] = "bbbb" self.assertRaises(exception.NovaException, pxe.get_tftp_image_info, self.instance, instance_type) # If an instance doesn't specify deploy_kernel_id or deploy_ramdisk_id, # but defaults are set in the config file, we should use those. # Here, we confirm both that all four values were set # and that the proper paths are getting set for all of them CONF.baremetal.deploy_kernel = "cccc" CONF.baremetal.deploy_ramdisk = "dddd" base = os.path.join(CONF.baremetal.tftp_root, self.instance["uuid"]) res = pxe.get_tftp_image_info(self.instance, instance_type) expected = { "kernel": ["aaaa", os.path.join(base, "kernel")], "ramdisk": ["bbbb", os.path.join(base, "ramdisk")], "deploy_kernel": ["cccc", os.path.join(base, "deploy_kernel")], "deploy_ramdisk": ["dddd", os.path.join(base, "deploy_ramdisk")], } self.assertEqual(res, expected) # If deploy_kernel_id and deploy_ramdisk_id are specified on # image extra_specs, this should override any default configuration. # Note that it is passed on the 'instance' object, despite being # inherited from the instance_types_extra_specs table. extra_specs = {"baremetal:deploy_kernel_id": "eeee", "baremetal:deploy_ramdisk_id": "ffff"} instance_type["extra_specs"] = extra_specs res = pxe.get_tftp_image_info(self.instance, instance_type) self.assertEqual(res["deploy_kernel"][0], "eeee") self.assertEqual(res["deploy_ramdisk"][0], "ffff") # However, if invalid values are passed on the image extra_specs, # this should still raise an exception. extra_specs = {"baremetal:deploy_kernel_id": "", "baremetal:deploy_ramdisk_id": ""} instance_type["extra_specs"] = extra_specs self.assertRaises(exception.NovaException, pxe.get_tftp_image_info, self.instance, instance_type)
def _create_node(self, node_info=None, nic_info=None, ephemeral=True): result = {} if node_info is None: node_info = bm_db_utils.new_bm_node( id=123, service_host='test_host', cpus=2, memory_mb=2048, ) if nic_info is None: nic_info = [ {'address': '01:23:45:67:89:01', 'datapath_id': '0x1', 'port_no': 1}, {'address': '01:23:45:67:89:02', 'datapath_id': '0x2', 'port_no': 2}, ] result['node_info'] = node_info result['nic_info'] = nic_info result['node'] = db.bm_node_create(self.context, node_info) for nic in nic_info: db.bm_interface_create( self.context, result['node']['id'], nic['address'], nic['datapath_id'], nic['port_no'], ) if ephemeral: result['instance'] = utils.get_test_instance() else: flavor = utils.get_test_instance_type(options={'ephemeral_gb': 0}) result['instance'] = utils.get_test_instance(instance_type=flavor) result['instance']['node'] = result['node']['uuid'] result['spawn_params'] = dict( admin_password='******', block_device_info=None, context=self.context, image_meta=utils.get_test_image_info( None, result['instance']), injected_files=[('/fake/path', 'hello world')], instance=result['instance'], network_info=utils.get_test_network_info(), ) result['destroy_params'] = dict( context=self.context, instance=result['instance'], network_info=result['spawn_params']['network_info'], block_device_info=result['spawn_params']['block_device_info'], ) return result
def test_get_partition_sizes(self): # m1.tiny: 10GB root, 0GB swap self.instance['instance_type_id'] = 1 sizes = pxe.get_partition_sizes(self.instance) self.assertEqual(sizes[0], 10240) self.assertEqual(sizes[1], 1) # kinda.big: 40GB root, 1GB swap ref = utils.get_test_instance_type() self.instance['instance_type_id'] = ref['id'] self.instance['root_gb'] = ref['root_gb'] sizes = pxe.get_partition_sizes(self.instance) self.assertEqual(sizes[0], 40960) self.assertEqual(sizes[1], 1024)
def test_cache_tftp_images(self): self.instance["kernel_id"] = "aaaa" self.instance["ramdisk_id"] = "bbbb" instance_type = utils.get_test_instance_type() extra_specs = {"baremetal:deploy_kernel_id": "cccc", "baremetal:deploy_ramdisk_id": "dddd"} instance_type["extra_specs"] = extra_specs image_info = pxe.get_tftp_image_info(self.instance, instance_type) self.mox.StubOutWithMock(os, "makedirs") self.mox.StubOutWithMock(os.path, "exists") os.makedirs(os.path.join(CONF.baremetal.tftp_root, self.instance["uuid"])).AndReturn(True) for uuid, path in [image_info[label] for label in image_info]: os.path.exists(path).AndReturn(True) self.mox.ReplayAll() self.driver._cache_tftp_images(self.context, self.instance, image_info) self.mox.VerifyAll()
def test_cache_tftp_images(self): self.instance['kernel_id'] = 'aaaa' self.instance['ramdisk_id'] = 'bbbb' instance_type = utils.get_test_instance_type() extra_specs = { 'baremetal:deploy_kernel_id': 'cccc', 'baremetal:deploy_ramdisk_id': 'dddd', } instance_type['extra_specs'] = extra_specs image_info = pxe.get_tftp_image_info(self.instance, instance_type) self.mox.StubOutWithMock(os, 'makedirs') self.mox.StubOutWithMock(os.path, 'exists') os.makedirs(os.path.join(CONF.baremetal.tftp_root, self.instance['uuid'])).AndReturn(True) for uuid, path in [image_info[label] for label in image_info]: os.path.exists(path).AndReturn(True) self.mox.ReplayAll() self.driver._cache_tftp_images( self.context, self.instance, image_info) self.mox.VerifyAll()
def test_cache_tftp_images(self): self.instance['kernel_id'] = 'aaaa' self.instance['ramdisk_id'] = 'bbbb' instance_type = utils.get_test_instance_type() extra_specs = { 'baremetal:deploy_kernel_id': 'cccc', 'baremetal:deploy_ramdisk_id': 'dddd', } instance_type['extra_specs'] = extra_specs image_info = pxe.get_tftp_image_info(self.instance, instance_type) self.mox.StubOutWithMock(os, 'makedirs') self.mox.StubOutWithMock(os.path, 'exists') os.makedirs( os.path.join(CONF.baremetal.tftp_root, self.instance['uuid'])).AndReturn(True) for uuid, path in [image_info[label] for label in image_info]: os.path.exists(path).AndReturn(True) self.mox.ReplayAll() self.driver._cache_tftp_images(self.context, self.instance, image_info) self.mox.VerifyAll()
def test_migrate_disk_and_power_off(self): instance_ref, network_info = self._get_running_instance() instance_type_ref = test_utils.get_test_instance_type() self.connection.migrate_disk_and_power_off( self.ctxt, instance_ref, 'dest_host', instance_type_ref, network_info)
def test_get_tftp_image_info(self): instance_type = utils.get_test_instance_type() # Raises an exception when options are neither specified # on the instance nor in configuration file CONF.baremetal.deploy_kernel = None CONF.baremetal.deploy_ramdisk = None self.assertRaises(exception.NovaException, pxe.get_tftp_image_info, self.instance, instance_type) # Test that other non-true values also raise an exception CONF.baremetal.deploy_kernel = "" CONF.baremetal.deploy_ramdisk = "" self.assertRaises(exception.NovaException, pxe.get_tftp_image_info, self.instance, instance_type) # Even if the instance includes kernel_id and ramdisk_id, # we still need deploy_kernel_id and deploy_ramdisk_id. # If those aren't present in instance[], and not specified in # config file, then we raise an exception. self.instance['kernel_id'] = 'aaaa' self.instance['ramdisk_id'] = 'bbbb' self.assertRaises(exception.NovaException, pxe.get_tftp_image_info, self.instance, instance_type) # If an instance doesn't specify deploy_kernel_id or deploy_ramdisk_id, # but defaults are set in the config file, we should use those. # Here, we confirm both that all four values were set # and that the proper paths are getting set for all of them CONF.baremetal.deploy_kernel = 'cccc' CONF.baremetal.deploy_ramdisk = 'dddd' base = os.path.join(CONF.baremetal.tftp_root, self.instance['uuid']) res = pxe.get_tftp_image_info(self.instance, instance_type) expected = { 'kernel': ['aaaa', os.path.join(base, 'kernel')], 'ramdisk': ['bbbb', os.path.join(base, 'ramdisk')], 'deploy_kernel': ['cccc', os.path.join(base, 'deploy_kernel')], 'deploy_ramdisk': ['dddd', os.path.join(base, 'deploy_ramdisk')], } self.assertEqual(res, expected) # If deploy_kernel_id and deploy_ramdisk_id are specified on # image extra_specs, this should override any default configuration. # Note that it is passed on the 'instance' object, despite being # inherited from the instance_types_extra_specs table. extra_specs = { 'baremetal:deploy_kernel_id': 'eeee', 'baremetal:deploy_ramdisk_id': 'ffff', } instance_type['extra_specs'] = extra_specs res = pxe.get_tftp_image_info(self.instance, instance_type) self.assertEqual(res['deploy_kernel'][0], 'eeee') self.assertEqual(res['deploy_ramdisk'][0], 'ffff') # However, if invalid values are passed on the image extra_specs, # this should still raise an exception. extra_specs = { 'baremetal:deploy_kernel_id': '', 'baremetal:deploy_ramdisk_id': '', } instance_type['extra_specs'] = extra_specs self.assertRaises(exception.NovaException, pxe.get_tftp_image_info, self.instance, instance_type)