def setUp(self): super(FloatingIpTest, self).setUp() self.stubs.Set(network.api.API, "get_fixed_ip", network_api_get_fixed_ip) self.stubs.Set(compute.api.API, "get", compute_api_get) self.stubs.Set(network.api.API, "get_floating_ip", network_api_get_floating_ip) self.stubs.Set(network.api.API, "get_floating_ip_by_address", network_api_get_floating_ip_by_address) self.stubs.Set(network.api.API, "get_floating_ips_by_project", network_api_get_floating_ips_by_project) self.stubs.Set(network.api.API, "release_floating_ip", network_api_release) self.stubs.Set(network.api.API, "disassociate_floating_ip", network_api_disassociate) self.stubs.Set(network.api.API, "get_instance_id_by_floating_address", get_instance_by_floating_ip_addr) self.stubs.Set(compute_utils, "get_nw_info_for_instance", stub_nw_info(self.stubs)) fake_network.stub_out_nw_api_get_instance_nw_info(self.stubs, spectacular=True) self.stubs.Set(db, 'instance_get', fake_instance_get) self.context = context.get_admin_context() self._create_floating_ips() self.controller = floating_ips.FloatingIPController() self.manager = floating_ips.FloatingIPActionController()
def setUp(self): super(OpenStackMetadataTestCase, self).setUp() self.context = context.RequestContext('fake', 'fake') self.instance = fake_inst_obj(self.context) self.instance['system_metadata'] = get_default_sys_meta() self.flags(use_local=True, group='conductor') fake_network.stub_out_nw_api_get_instance_nw_info(self.stubs)
def setUp(self): super(OpenStackMetadataTestCase, self).setUp() self.instance = INSTANCES[0] self.instance['system_metadata'] = get_default_sys_meta() self.flags(use_local=True, group='conductor') fake_network.stub_out_nw_api_get_instance_nw_info(self.stubs, spectacular=True)
def stub_out_nw_api(stubs, cls=None, private=None, publics=None): if not private: private = '192.168.0.3' if not publics: publics = ['1.2.3.4'] class Fake: def get_instance_nw_info(*args, **kwargs): pass def get_floating_ips_by_fixed_address(*args, **kwargs): return publics def validate_networks(self, context, networks, max_count): return max_count def create_pci_requests_for_sriov_ports(self, context, system_metadata, requested_networks): pass if cls is None: cls = Fake stubs.Set(network_api, 'API', cls) fake_network.stub_out_nw_api_get_instance_nw_info(stubs)
def setUp(self): super(MetadataHandlerTestCase, self).setUp() fake_network.stub_out_nw_api_get_instance_nw_info(self.stubs, spectacular=True) self.instance = INSTANCES[0] self.flags(use_local=True, group="conductor") self.mdinst = fake_InstanceMetadata(self.stubs, self.instance, address=None, sgroups=None)
def setUp(self): super(ExtendedFloatingIpTest, self).setUp() self.stubs.Set(compute.api.API, "get", compute_api_get) self.stubs.Set(network.api.API, "get_floating_ip", network_api_get_floating_ip) self.stubs.Set(network.api.API, "get_floating_ip_by_address", network_api_get_floating_ip_by_address) self.stubs.Set(network.api.API, "get_floating_ips_by_project", network_api_get_floating_ips_by_project) self.stubs.Set(network.api.API, "release_floating_ip", network_api_release) self.stubs.Set(network.api.API, "disassociate_floating_ip", network_api_disassociate) self.stubs.Set(network.api.API, "get_instance_id_by_floating_address", get_instance_by_floating_ip_addr) self.stubs.Set(compute_utils, "get_nw_info_for_instance", stub_nw_info(self.stubs)) self.flags( osapi_compute_extension=[ 'nova.api.openstack.compute.contrib.select_extensions' ], osapi_compute_ext_list=['Floating_ips', 'Extended_floating_ips']) fake_network.stub_out_nw_api_get_instance_nw_info(self.stubs) self.stubs.Set(db, 'instance_get', fake_instance_get) self.context = context.get_admin_context() self._create_floating_ips() self.ext_mgr = extensions.ExtensionManager() self.ext_mgr.extensions = {} self.ext_mgr.extensions['os-floating-ips'] = True self.ext_mgr.extensions['os-extended-floating-ips'] = True self.controller = floating_ips.FloatingIPController() self.manager = floating_ips.FloatingIPActionController(self.ext_mgr)
def setUp(self): super(OpenStackMetadataTestCase, self).setUp() self.context = context.RequestContext('fake', 'fake') self.instance = fake_inst_obj(self.context) self.instance['system_metadata'] = get_default_sys_meta() self.flags(use_local=True, group='conductor') fake_network.stub_out_nw_api_get_instance_nw_info(self.stubs)
def setUp(self): super(OpenStackMetadataTestCase, self).setUp() self.instance = INSTANCES[0] self.instance['system_metadata'] = get_default_sys_meta() self.flags(use_local=True, group='conductor') fake_network.stub_out_nw_api_get_instance_nw_info(self.stubs, spectacular=True)
def setUp(self): super(MetadataPasswordTestCase, self).setUp() fake_network.stub_out_nw_api_get_instance_nw_info(self.stubs, spectacular=True) self.instance = copy(INSTANCES[0]) self.mdinst = fake_InstanceMetadata(self.stubs, self.instance, address=None, sgroups=None)
def setUp(self): super(ExtendedFloatingIpTest, self).setUp() self.stubs.Set(compute.api.API, "get", compute_api_get) self.stubs.Set(network.api.API, "get_floating_ip", network_api_get_floating_ip) self.stubs.Set(network.api.API, "get_floating_ip_by_address", network_api_get_floating_ip_by_address) self.stubs.Set(network.api.API, "get_floating_ips_by_project", network_api_get_floating_ips_by_project) self.stubs.Set(network.api.API, "release_floating_ip", network_api_release) self.stubs.Set(network.api.API, "disassociate_floating_ip", network_api_disassociate) self.stubs.Set(network.api.API, "get_instance_id_by_floating_address", get_instance_by_floating_ip_addr) self.stubs.Set(compute_utils, "get_nw_info_for_instance", stub_nw_info(self.stubs)) self.flags( osapi_compute_extension=["nova.api.openstack.compute.contrib.select_extensions"], osapi_compute_ext_list=["Floating_ips", "Extended_floating_ips"], ) fake_network.stub_out_nw_api_get_instance_nw_info(self.stubs) self.stubs.Set(db, "instance_get", fake_instance_get) self.context = context.get_admin_context() self._create_floating_ips() self.ext_mgr = extensions.ExtensionManager() self.ext_mgr.extensions = {} self.ext_mgr.extensions["os-floating-ips"] = True self.ext_mgr.extensions["os-extended-floating-ips"] = True self.controller = floating_ips.FloatingIPController() self.manager = floating_ips.FloatingIPActionController(self.ext_mgr)
def setUp(self): super(FloatingIpTest, self).setUp() self.stubs.Set(compute.api.API, "get", compute_api_get) self.stubs.Set(network.api.API, "get_floating_ip", network_api_get_floating_ip) self.stubs.Set(network.api.API, "get_floating_ip_by_address", network_api_get_floating_ip_by_address) self.stubs.Set(network.api.API, "get_floating_ips_by_project", network_api_get_floating_ips_by_project) self.stubs.Set(network.api.API, "release_floating_ip", network_api_release) self.stubs.Set(network.api.API, "disassociate_floating_ip", network_api_disassociate) self.stubs.Set(network.api.API, "get_instance_id_by_floating_address", get_instance_by_floating_ip_addr) self.stubs.Set(compute_utils, "get_nw_info_for_instance", stub_nw_info(self.stubs)) self.flags( osapi_compute_extension=[ 'nova.api.openstack.compute.contrib.select_extensions'], osapi_compute_ext_list=['Floating_ips']) fake_network.stub_out_nw_api_get_instance_nw_info(self.stubs, spectacular=True) self.stubs.Set(db, 'instance_get', fake_instance_get) self.context = context.get_admin_context() self._create_floating_ips() self.controller = floating_ips.FloatingIPController() self.manager = floating_ips.FloatingIPActionController()
def setUp(self): super(FloatingIpTest, self).setUp() self.stubs.Set(network.api.API, "get_fixed_ip", network_api_get_fixed_ip) self.stubs.Set(compute.api.API, "get", compute_api_get) self.stubs.Set(network.api.API, "get_floating_ip", network_api_get_floating_ip) self.stubs.Set(network.api.API, "get_floating_ip_by_address", network_api_get_floating_ip_by_address) self.stubs.Set(network.api.API, "get_floating_ips_by_project", network_api_get_floating_ips_by_project) self.stubs.Set(network.api.API, "release_floating_ip", network_api_release) self.stubs.Set(network.api.API, "disassociate_floating_ip", network_api_disassociate) self.stubs.Set(compute_utils, "get_nw_info_for_instance", stub_nw_info(self.stubs)) fake_network.stub_out_nw_api_get_instance_nw_info(self.stubs, spectacular=True) self.stubs.Set(db, 'instance_get', fake_instance_get) self.context = context.get_admin_context() self._create_floating_ip() self.controller = floating_ips.FloatingIPController() self.manager = floating_ips.FloatingIPActionController()
def setUp(self): super(MetadataTestCase, self).setUp() self.context = context.RequestContext("fake", "fake") self.instance = fake_inst_obj(self.context) self.instance.system_metadata = get_default_sys_meta() self.flags(use_local=True, group="conductor") fake_network.stub_out_nw_api_get_instance_nw_info(self.stubs)
def setUp(self): super(MetadataPasswordTestCase, self).setUp() fake_network.stub_out_nw_api_get_instance_nw_info(self.stubs, spectacular=True) self.instance = copy.copy(INSTANCES[0]) self.instance["system_metadata"] = get_default_sys_meta() self.flags(use_local=True, group="conductor") self.mdinst = fake_InstanceMetadata(self.stubs, self.instance, address=None, sgroups=None) self.flags(use_local=True, group="conductor")
def setUp(self): super(MetadataPasswordTestCase, self).setUp() fake_network.stub_out_nw_api_get_instance_nw_info(self.stubs) self.instance = copy.copy(INSTANCES[0]) self.instance['system_metadata'] = get_default_sys_meta() self.flags(use_local=True, group='conductor') self.mdinst = fake_InstanceMetadata(self.stubs, self.instance, address=None, sgroups=None) self.flags(use_local=True, group='conductor')
def setUp(self): super(MetadataHandlerTestCase, self).setUp() fake_network.stub_out_nw_api_get_instance_nw_info(self.stubs) self.instance = INSTANCES[0] self.instance['system_metadata'] = get_default_sys_meta() self.flags(use_local=True, group='conductor') self.mdinst = fake_InstanceMetadata(self.stubs, self.instance, address=None, sgroups=None)
def setUp(self): super(MetadataPasswordTestCase, self).setUp() fake_network.stub_out_nw_api_get_instance_nw_info(self.stubs, spectacular=True) self.instance = copy.copy(INSTANCES[0]) self.mdinst = fake_InstanceMetadata(self.stubs, self.instance, address=None, sgroups=None)
def setUp(self): super(MetadataPasswordTestCase, self).setUp() fake_network.stub_out_nw_api_get_instance_nw_info(self.stubs) self.context = context.RequestContext('fake', 'fake') self.instance = fake_inst_obj(self.context) self.instance.system_metadata = get_default_sys_meta() self.flags(use_local=True, group='conductor') self.mdinst = fake_InstanceMetadata(self.stubs, self.instance, address=None, sgroups=None) self.flags(use_local=True, group='conductor')
def setUp(self): super(MetadataPasswordTestCase, self).setUp() fake_network.stub_out_nw_api_get_instance_nw_info(self.stubs) self.context = context.RequestContext('fake', 'fake') self.instance = fake_inst_obj(self.context) self.instance.system_metadata = get_default_sys_meta() self.flags(use_local=True, group='conductor') self.mdinst = fake_InstanceMetadata(self.stubs, self.instance, address=None, sgroups=None) self.flags(use_local=True, group='conductor')
def setUp(self): super(MetadataTestCase, self).setUp() self.instance = ({ 'id': 1, 'uuid': 'b65cee2f-8c69-4aeb-be2f-f79742548fc2', 'name': 'fake', 'project_id': 'test', 'key_name': None, 'host': 'test', 'launch_index': 1, 'instance_type': { 'name': 'm1.tiny' }, 'reservation_id': 'r-xxxxxxxx', 'user_data': '', 'image_ref': 7, 'vcpus': 1, 'fixed_ips': [], 'root_device_name': '/dev/sda1', 'info_cache': { 'network_info': [] }, 'hostname': 'test' }) def fake_get_floating_ips_by_fixed_address(self, context, fixed_ip): return ['1.2.3.4', '5.6.7.8'] def instance_get(*args, **kwargs): return self.instance def instance_get_list(*args, **kwargs): return [self.instance] def get_fixed_ip_by_address(*args, **kwargs): return {'instance_id': self.instance['id']} fake_network.stub_out_nw_api_get_instance_nw_info(self.stubs, spectacular=True) self.stubs.Set(network.API, 'get_floating_ips_by_fixed_address', fake_get_floating_ips_by_fixed_address) self.stubs.Set(network.API, 'get_fixed_ip_by_address', get_fixed_ip_by_address) self.stubs.Set(api, 'instance_get', instance_get) self.stubs.Set(api, 'instance_get_all_by_filters', instance_get_list) self.app = handler.MetadataRequestHandler() network_manager = fake_network.FakeNetworkManager() self.stubs.Set(self.app.compute_api.network_api, 'get_instance_uuids_by_ip_filter', network_manager.get_instance_uuids_by_ip_filter)
def stub_out_nw_api(stubs, cls=None, private=None, publics=None): if not private: private = '192.168.0.3' if not publics: publics = ['1.2.3.4'] class Fake: def get_instance_nw_info(*args, **kwargs): pass def get_floating_ips_by_fixed_address(*args, **kwargs): return publics if cls is None: cls = Fake stubs.Set(network_api, 'API', cls) fake_network.stub_out_nw_api_get_instance_nw_info(stubs, spectacular=True)
def stub_out_nw_api(stubs, cls=None, private=None, publics=None): if not private: private = '192.168.0.3' if not publics: publics = ['1.2.3.4'] class Fake: def get_instance_nw_info(*args, **kwargs): pass def get_floating_ips_by_fixed_address(*args, **kwargs): return publics if cls is None: cls = Fake stubs.Set(network_api, 'API', cls) fake_network.stub_out_nw_api_get_instance_nw_info(stubs, spectacular=True)
def setUp(self): super(MetadataTestCase, self).setUp() self.instance = { "id": 1, "uuid": "b65cee2f-8c69-4aeb-be2f-f79742548fc2", "name": "fake", "project_id": "test", "key_name": None, "host": "test", "launch_index": 1, "instance_type": {"name": "m1.tiny"}, "reservation_id": "r-xxxxxxxx", "user_data": "", "image_ref": 7, "vcpus": 1, "fixed_ips": [], "root_device_name": "/dev/sda1", "info_cache": {"network_info": []}, "hostname": "test", } def fake_get_floating_ips_by_fixed_address(self, context, fixed_ip): return ["1.2.3.4", "5.6.7.8"] def instance_get(*args, **kwargs): return self.instance def instance_get_list(*args, **kwargs): return [self.instance] def get_fixed_ip_by_address(*args, **kwargs): return {"instance_id": self.instance["id"]} fake_network.stub_out_nw_api_get_instance_nw_info(self.stubs, spectacular=True) self.stubs.Set(network.API, "get_floating_ips_by_fixed_address", fake_get_floating_ips_by_fixed_address) self.stubs.Set(network.API, "get_fixed_ip_by_address", get_fixed_ip_by_address) self.stubs.Set(api, "instance_get", instance_get) self.stubs.Set(api, "instance_get_all_by_filters", instance_get_list) self.app = handler.MetadataRequestHandler() network_manager = fake_network.FakeNetworkManager() self.stubs.Set( self.app.compute_api.network_api, "get_instance_uuids_by_ip_filter", network_manager.get_instance_uuids_by_ip_filter, )
def setUp(self): super(MetadataTestCase, self).setUp() self.instance = ({'id': 1, 'name': 'fake', 'project_id': 'test', 'key_name': None, 'host': 'test', 'launch_index': 1, 'instance_type': {'name': 'm1.tiny'}, 'reservation_id': 'r-xxxxxxxx', 'user_data': '', 'image_ref': 7, 'vcpus': 1, 'fixed_ips': [], 'root_device_name': '/dev/sda1', 'info_cache': {'network_info': []}, 'hostname': 'test'}) def fake_get_floating_ips_by_fixed_address(self, context, fixed_ip): return ['1.2.3.4', '5.6.7.8'] def instance_get(*args, **kwargs): return self.instance def instance_get_list(*args, **kwargs): return [self.instance] def get_fixed_ip_by_address(*args, **kwargs): return {'instance_id': self.instance['id']} fake_network.stub_out_nw_api_get_instance_nw_info(self.stubs, spectacular=True) self.stubs.Set(network.API, 'get_floating_ips_by_fixed_address', fake_get_floating_ips_by_fixed_address) self.stubs.Set(network.API, 'get_fixed_ip_by_address', get_fixed_ip_by_address) self.stubs.Set(api, 'instance_get', instance_get) self.stubs.Set(api, 'instance_get_all_by_filters', instance_get_list) self.app = handler.MetadataRequestHandler() network_manager = fake_network.FakeNetworkManager() self.stubs.Set(self.app.compute_api.network_api, 'get_instance_uuids_by_ip_filter', network_manager.get_instance_uuids_by_ip_filter)
def stub_out_nw_api(stubs, cls=None, private=None, publics=None): if not private: private = '192.168.0.3' if not publics: publics = ['1.2.3.4'] class Fake: def get_instance_nw_info(*args, **kwargs): pass def get_floating_ips_by_fixed_address(*args, **kwargs): return publics def validate_networks(self, context, networks, max_count): return max_count if cls is None: cls = Fake stubs.Set(network_api, 'API', cls) fake_network.stub_out_nw_api_get_instance_nw_info(stubs)
def stub_out_nw_api(stubs, cls=None, private=None, publics=None): if not private: private = "192.168.0.3" if not publics: publics = ["1.2.3.4"] class Fake: def get_instance_nw_info(*args, **kwargs): pass def get_floating_ips_by_fixed_address(*args, **kwargs): return publics def validate_networks(*args, **kwargs): pass if cls is None: cls = Fake stubs.Set(network_api, "API", cls) fake_network.stub_out_nw_api_get_instance_nw_info(stubs)
def stub_out_nw_api_get_instance_nw_info(stubs, num_networks=1, func=None): fake_network.stub_out_nw_api_get_instance_nw_info(stubs, spectacular=True)
def _setup_stubs(self): db_fakes.stub_out_db_instance_api(self.stubs) fake_image.stub_out_image_service(self.stubs) fake_network.stub_out_nw_api_get_instance_nw_info(self.stubs) def fake_fetch(context, image_id, target, user, project): self._fetched_image = target self.stubs.Set(images, 'fetch', fake_fetch) def fake_get_remote_image_service(context, name): class FakeGlanceImageService(object): def update(self_fake, context, image_id, image_metadata, f): if self._update_image_raise_exception: raise vmutils.HyperVException( "Simulated update failure") self._image_metadata = image_metadata return (FakeGlanceImageService(), 1) self.stubs.Set(glance, 'get_remote_image_service', fake_get_remote_image_service) def fake_sleep(ms): pass self.stubs.Set(time, 'sleep', fake_sleep) self.stubs.Set(pathutils, 'PathUtils', fake.PathUtils) self._mox.StubOutWithMock(fake.PathUtils, 'open') self._mox.StubOutWithMock(fake.PathUtils, 'copyfile') self._mox.StubOutWithMock(fake.PathUtils, 'rmtree') self._mox.StubOutWithMock(fake.PathUtils, 'copy') self._mox.StubOutWithMock(fake.PathUtils, 'remove') self._mox.StubOutWithMock(fake.PathUtils, 'rename') self._mox.StubOutWithMock(fake.PathUtils, 'makedirs') self._mox.StubOutWithMock(fake.PathUtils, 'get_instance_migr_revert_dir') self._mox.StubOutWithMock(vmutils.VMUtils, 'vm_exists') self._mox.StubOutWithMock(vmutils.VMUtils, 'create_vm') self._mox.StubOutWithMock(vmutils.VMUtils, 'destroy_vm') self._mox.StubOutWithMock(vmutils.VMUtils, 'attach_ide_drive') self._mox.StubOutWithMock(vmutils.VMUtils, 'create_scsi_controller') self._mox.StubOutWithMock(vmutils.VMUtils, 'create_nic') self._mox.StubOutWithMock(vmutils.VMUtils, 'set_vm_state') self._mox.StubOutWithMock(vmutils.VMUtils, 'list_instances') self._mox.StubOutWithMock(vmutils.VMUtils, 'get_vm_summary_info') self._mox.StubOutWithMock(vmutils.VMUtils, 'take_vm_snapshot') self._mox.StubOutWithMock(vmutils.VMUtils, 'remove_vm_snapshot') self._mox.StubOutWithMock(vmutils.VMUtils, 'set_nic_connection') self._mox.StubOutWithMock(vmutils.VMUtils, 'get_vm_iscsi_controller') self._mox.StubOutWithMock(vmutils.VMUtils, 'get_vm_ide_controller') self._mox.StubOutWithMock(vmutils.VMUtils, 'get_attached_disks_count') self._mox.StubOutWithMock(vmutils.VMUtils, 'attach_volume_to_controller') self._mox.StubOutWithMock(vmutils.VMUtils, 'get_mounted_disk_by_drive_number') self._mox.StubOutWithMock(vmutils.VMUtils, 'detach_vm_disk') self._mox.StubOutWithMock(vmutils.VMUtils, 'get_vm_storage_paths') self._mox.StubOutWithMock(vhdutils.VHDUtils, 'create_differencing_vhd') self._mox.StubOutWithMock(vhdutils.VHDUtils, 'reconnect_parent_vhd') self._mox.StubOutWithMock(vhdutils.VHDUtils, 'merge_vhd') self._mox.StubOutWithMock(vhdutils.VHDUtils, 'get_vhd_parent_path') self._mox.StubOutWithMock(vhdutils.VHDUtils, 'get_vhd_info') self._mox.StubOutWithMock(hostutils.HostUtils, 'get_cpus_info') self._mox.StubOutWithMock(hostutils.HostUtils, 'is_cpu_feature_present') self._mox.StubOutWithMock(hostutils.HostUtils, 'get_memory_info') self._mox.StubOutWithMock(hostutils.HostUtils, 'get_volume_info') self._mox.StubOutWithMock(hostutils.HostUtils, 'get_windows_version') self._mox.StubOutWithMock(hostutils.HostUtils, 'get_local_ips') self._mox.StubOutWithMock(networkutils.NetworkUtils, 'get_external_vswitch') self._mox.StubOutWithMock(networkutils.NetworkUtils, 'create_vswitch_port') self._mox.StubOutWithMock(livemigrationutils.LiveMigrationUtils, 'live_migrate_vm') self._mox.StubOutWithMock(livemigrationutils.LiveMigrationUtils, 'check_live_migration_config') self._mox.StubOutWithMock(basevolumeutils.BaseVolumeUtils, 'volume_in_mapping') self._mox.StubOutWithMock(basevolumeutils.BaseVolumeUtils, 'get_session_id_from_mounted_disk') self._mox.StubOutWithMock(basevolumeutils.BaseVolumeUtils, 'get_device_number_for_target') self._mox.StubOutWithMock(volumeutils.VolumeUtils, 'login_storage_target') self._mox.StubOutWithMock(volumeutils.VolumeUtils, 'logout_storage_target') self._mox.StubOutWithMock(volumeutils.VolumeUtils, 'execute_log_out') self._mox.StubOutWithMock(volumeutilsv2.VolumeUtilsV2, 'login_storage_target') self._mox.StubOutWithMock(volumeutilsv2.VolumeUtilsV2, 'logout_storage_target') self._mox.StubOutWithMock(volumeutilsv2.VolumeUtilsV2, 'execute_log_out') self._mox.StubOutClassWithMocks(instance_metadata, 'InstanceMetadata') self._mox.StubOutWithMock(instance_metadata.InstanceMetadata, 'metadata_for_config_drive') # Can't use StubOutClassWithMocks due to __exit__ and __enter__ self._mox.StubOutWithMock(configdrive, 'ConfigDriveBuilder') self._mox.StubOutWithMock(configdrive.ConfigDriveBuilder, 'make_drive') self._mox.StubOutWithMock(utils, 'execute')
def setUp(self): super(OpenStackMetadataTestCase, self).setUp() self.instance = INSTANCES[0] fake_network.stub_out_nw_api_get_instance_nw_info(self.stubs, spectacular=True)
def _setup_stubs(self): db_fakes.stub_out_db_instance_api(self.stubs) fake_image.stub_out_image_service(self.stubs) fake_network.stub_out_nw_api_get_instance_nw_info(self.stubs) def fake_dumps(msg, default=None, **kwargs): return '""' self.stubs.Set(json, 'dumps', fake_dumps) def fake_fetch(context, image_id, target, user, project): self._fetched_image = target if not os.path.exists(target): self._hypervutils.create_vhd(target) self.stubs.Set(images, 'fetch', fake_fetch) def fake_get_remote_image_service(context, name): class FakeGlanceImageService(object): def update(self_fake, context, image_id, image_metadata, f): if self._update_image_raise_exception: raise vmutils.HyperVException( "Simulated update failure") self._image_metadata = image_metadata return (FakeGlanceImageService(), 1) self.stubs.Set(glance, 'get_remote_image_service', fake_get_remote_image_service) # Modules to mock modules_to_mock = [ 'wmi', 'os', 'shutil', 'uuid', 'time', 'multiprocessing', '_winreg', 'nova.virt.configdrive', 'nova.utils', 'ctypes' ] # Modules in which the mocks are going to be injected from nova.virt.hyperv import baseops from nova.virt.hyperv import basevolumeutils from nova.virt.hyperv import hostops from nova.virt.hyperv import livemigrationops from nova.virt.hyperv import snapshotops from nova.virt.hyperv import vmops from nova.virt.hyperv import volumeops from nova.virt.hyperv import volumeutils from nova.virt.hyperv import volumeutilsV2 modules_to_test = [ driver_hyperv, basevolumeutils, baseops, hostops, vmops, vmutils, volumeops, volumeutils, volumeutilsV2, snapshotops, livemigrationops, hypervutils, db_fakes, sys.modules[__name__] ] self._inject_mocks_in_modules(modules_to_mock, modules_to_test) if isinstance(snapshotops.wmi, mockproxy.Mock): from nova.virt.hyperv import ioutils import StringIO def fake_open(name, mode): return StringIO.StringIO("fake file content") self.stubs.Set(ioutils, 'open', fake_open)
def _setup_stubs(self): db_fakes.stub_out_db_instance_api(self.stubs) fake_image.stub_out_image_service(self.stubs) fake_network.stub_out_nw_api_get_instance_nw_info(self.stubs) def fake_fetch(context, image_id, target, user, project): self._fetched_image = target self.stubs.Set(images, 'fetch', fake_fetch) def fake_get_remote_image_service(context, name): class FakeGlanceImageService(object): def update(self_fake, context, image_id, image_metadata, f): if self._update_image_raise_exception: raise vmutils.HyperVException( "Simulated update failure") self._image_metadata = image_metadata return (FakeGlanceImageService(), 1) self.stubs.Set(glance, 'get_remote_image_service', fake_get_remote_image_service) def fake_sleep(ms): pass self.stubs.Set(time, 'sleep', fake_sleep) def fake_vmutils__init__(self, host='.'): pass vmutils.VMUtils.__init__ = fake_vmutils__init__ def fake_get_volume_utils(self): return volumeutils.VolumeUtils() volumeops.VolumeOps._get_volume_utils = fake_get_volume_utils self.stubs.Set(pathutils, 'PathUtils', fake.PathUtils) self._mox.StubOutWithMock(fake.PathUtils, 'open') self._mox.StubOutWithMock(fake.PathUtils, 'copyfile') self._mox.StubOutWithMock(fake.PathUtils, 'rmtree') self._mox.StubOutWithMock(fake.PathUtils, 'copy') self._mox.StubOutWithMock(fake.PathUtils, 'remove') self._mox.StubOutWithMock(fake.PathUtils, 'rename') self._mox.StubOutWithMock(fake.PathUtils, 'makedirs') self._mox.StubOutWithMock(fake.PathUtils, 'get_instance_migr_revert_dir') self._mox.StubOutWithMock(fake.PathUtils, 'get_instance_dir') self._mox.StubOutWithMock(vmutils.VMUtils, 'vm_exists') self._mox.StubOutWithMock(vmutils.VMUtils, 'create_vm') self._mox.StubOutWithMock(vmutils.VMUtils, 'destroy_vm') self._mox.StubOutWithMock(vmutils.VMUtils, 'attach_ide_drive') self._mox.StubOutWithMock(vmutils.VMUtils, 'create_scsi_controller') self._mox.StubOutWithMock(vmutils.VMUtils, 'create_nic') self._mox.StubOutWithMock(vmutils.VMUtils, 'set_vm_state') self._mox.StubOutWithMock(vmutils.VMUtils, 'list_instances') self._mox.StubOutWithMock(vmutils.VMUtils, 'get_vm_summary_info') self._mox.StubOutWithMock(vmutils.VMUtils, 'take_vm_snapshot') self._mox.StubOutWithMock(vmutils.VMUtils, 'remove_vm_snapshot') self._mox.StubOutWithMock(vmutils.VMUtils, 'set_nic_connection') self._mox.StubOutWithMock(vmutils.VMUtils, 'get_vm_scsi_controller') self._mox.StubOutWithMock(vmutils.VMUtils, 'get_vm_ide_controller') self._mox.StubOutWithMock(vmutils.VMUtils, 'get_attached_disks_count') self._mox.StubOutWithMock(vmutils.VMUtils, 'attach_volume_to_controller') self._mox.StubOutWithMock(vmutils.VMUtils, 'get_mounted_disk_by_drive_number') self._mox.StubOutWithMock(vmutils.VMUtils, 'detach_vm_disk') self._mox.StubOutWithMock(vmutils.VMUtils, 'get_vm_storage_paths') self._mox.StubOutWithMock(vmutils.VMUtils, 'get_controller_volume_paths') self._mox.StubOutWithMock(vhdutils.VHDUtils, 'create_differencing_vhd') self._mox.StubOutWithMock(vhdutils.VHDUtils, 'reconnect_parent_vhd') self._mox.StubOutWithMock(vhdutils.VHDUtils, 'merge_vhd') self._mox.StubOutWithMock(vhdutils.VHDUtils, 'get_vhd_parent_path') self._mox.StubOutWithMock(vhdutils.VHDUtils, 'get_vhd_info') self._mox.StubOutWithMock(vhdutils.VHDUtils, 'resize_vhd') self._mox.StubOutWithMock(vhdutils.VHDUtils, 'validate_vhd') self._mox.StubOutWithMock(hostutils.HostUtils, 'get_cpus_info') self._mox.StubOutWithMock(hostutils.HostUtils, 'is_cpu_feature_present') self._mox.StubOutWithMock(hostutils.HostUtils, 'get_memory_info') self._mox.StubOutWithMock(hostutils.HostUtils, 'get_volume_info') self._mox.StubOutWithMock(hostutils.HostUtils, 'get_windows_version') self._mox.StubOutWithMock(hostutils.HostUtils, 'get_local_ips') self._mox.StubOutWithMock(networkutils.NetworkUtils, 'get_external_vswitch') self._mox.StubOutWithMock(networkutils.NetworkUtils, 'create_vswitch_port') self._mox.StubOutWithMock(livemigrationutils.LiveMigrationUtils, 'live_migrate_vm') self._mox.StubOutWithMock(livemigrationutils.LiveMigrationUtils, 'check_live_migration_config') self._mox.StubOutWithMock(basevolumeutils.BaseVolumeUtils, 'volume_in_mapping') self._mox.StubOutWithMock(basevolumeutils.BaseVolumeUtils, 'get_session_id_from_mounted_disk') self._mox.StubOutWithMock(basevolumeutils.BaseVolumeUtils, 'get_device_number_for_target') self._mox.StubOutWithMock(basevolumeutils.BaseVolumeUtils, 'get_target_from_disk_path') self._mox.StubOutWithMock(volumeutils.VolumeUtils, 'login_storage_target') self._mox.StubOutWithMock(volumeutils.VolumeUtils, 'logout_storage_target') self._mox.StubOutWithMock(volumeutils.VolumeUtils, 'execute_log_out') self._mox.StubOutWithMock(volumeutilsv2.VolumeUtilsV2, 'login_storage_target') self._mox.StubOutWithMock(volumeutilsv2.VolumeUtilsV2, 'logout_storage_target') self._mox.StubOutWithMock(volumeutilsv2.VolumeUtilsV2, 'execute_log_out') self._mox.StubOutClassWithMocks(instance_metadata, 'InstanceMetadata') self._mox.StubOutWithMock(instance_metadata.InstanceMetadata, 'metadata_for_config_drive') # Can't use StubOutClassWithMocks due to __exit__ and __enter__ self._mox.StubOutWithMock(configdrive, 'ConfigDriveBuilder') self._mox.StubOutWithMock(configdrive.ConfigDriveBuilder, 'make_drive') self._mox.StubOutWithMock(utils, 'execute')
def setUp(self): super(MetadataTestCase, self).setUp() self.instance = INSTANCES[0] self.flags(use_local=True, group='conductor') fake_network.stub_out_nw_api_get_instance_nw_info(self.stubs, spectacular=True)
def stub_out_nw_api_get_instance_nw_info(stubs, num_networks=1, func=None): fake_network.stub_out_nw_api_get_instance_nw_info(stubs, spectacular=True)
def _setup_stubs(self): db_fakes.stub_out_db_instance_api(self.stubs) fake_image.stub_out_image_service(self.stubs) fake_network.stub_out_nw_api_get_instance_nw_info(self.stubs) def fake_dumps(msg, default=None, **kwargs): return '""' self.stubs.Set(json, 'dumps', fake_dumps) def fake_fetch(context, image_id, target, user, project): self._fetched_image = target if not os.path.exists(target): self._hypervutils.create_vhd(target) self.stubs.Set(images, 'fetch', fake_fetch) def fake_get_remote_image_service(context, name): class FakeGlanceImageService(object): def update(self_fake, context, image_id, image_metadata, f): if self._update_image_raise_exception: raise vmutils.HyperVException( "Simulated update failure") self._image_metadata = image_metadata return (FakeGlanceImageService(), 1) self.stubs.Set(glance, 'get_remote_image_service', fake_get_remote_image_service) # Modules to mock modules_to_mock = [ 'wmi', 'os', 'shutil', 'uuid', 'time', 'multiprocessing', '_winreg', 'nova.virt.configdrive', 'nova.utils', 'ctypes' ] # Modules in which the mocks are going to be injected from nova.virt.hyperv import baseops from nova.virt.hyperv import basevolumeutils from nova.virt.hyperv import hostops from nova.virt.hyperv import livemigrationops from nova.virt.hyperv import snapshotops from nova.virt.hyperv import vmops from nova.virt.hyperv import volumeops from nova.virt.hyperv import volumeutils from nova.virt.hyperv import volumeutilsV2 modules_to_test = [ driver_hyperv, basevolumeutils, baseops, hostops, vmops, vmutils, volumeops, volumeutils, volumeutilsV2, snapshotops, livemigrationops, hypervutils, db_fakes, sys.modules[__name__] ] self._inject_mocks_in_modules(modules_to_mock, modules_to_test) if isinstance(snapshotops.wmi, mockproxy.Mock): from nova.virt.hyperv import ioutils import StringIO def fake_open(name, mode): return StringIO.StringIO("fake file content") self.stubs.Set(ioutils, 'open', fake_open)
def setUp(self): super(OpenStackMetadataTestCase, self).setUp() self.instance = INSTANCES[0] fake_network.stub_out_nw_api_get_instance_nw_info(self.stubs, spectacular=True)
def _setup_stubs(self): db_fakes.stub_out_db_instance_api(self.stubs) fake_image.stub_out_image_service(self.stubs) fake_network.stub_out_nw_api_get_instance_nw_info(self.stubs) def fake_fetch(context, image_id, target, user, project): self._fetched_image = target self.stubs.Set(images, "fetch", fake_fetch) def fake_get_remote_image_service(context, name): class FakeGlanceImageService(object): def update(self_fake, context, image_id, image_metadata, f): if self._update_image_raise_exception: raise vmutils.HyperVException("Simulated update failure") self._image_metadata = image_metadata return (FakeGlanceImageService(), 1) self.stubs.Set(glance, "get_remote_image_service", fake_get_remote_image_service) def fake_check_min_windows_version(fake_self, major, minor): return self._check_min_windows_version_satisfied self.stubs.Set(hostutils.HostUtils, "check_min_windows_version", fake_check_min_windows_version) def fake_sleep(ms): pass self.stubs.Set(time, "sleep", fake_sleep) def fake_vmutils__init__(self, host="."): pass vmutils.VMUtils.__init__ = fake_vmutils__init__ self.stubs.Set(pathutils, "PathUtils", fake.PathUtils) self._mox.StubOutWithMock(fake.PathUtils, "open") self._mox.StubOutWithMock(fake.PathUtils, "copyfile") self._mox.StubOutWithMock(fake.PathUtils, "rmtree") self._mox.StubOutWithMock(fake.PathUtils, "copy") self._mox.StubOutWithMock(fake.PathUtils, "remove") self._mox.StubOutWithMock(fake.PathUtils, "rename") self._mox.StubOutWithMock(fake.PathUtils, "makedirs") self._mox.StubOutWithMock(fake.PathUtils, "get_instance_migr_revert_dir") self._mox.StubOutWithMock(fake.PathUtils, "get_instance_dir") self._mox.StubOutWithMock(vmutils.VMUtils, "vm_exists") self._mox.StubOutWithMock(vmutils.VMUtils, "create_vm") self._mox.StubOutWithMock(vmutils.VMUtils, "destroy_vm") self._mox.StubOutWithMock(vmutils.VMUtils, "attach_ide_drive") self._mox.StubOutWithMock(vmutils.VMUtils, "create_scsi_controller") self._mox.StubOutWithMock(vmutils.VMUtils, "create_nic") self._mox.StubOutWithMock(vmutils.VMUtils, "set_vm_state") self._mox.StubOutWithMock(vmutils.VMUtils, "list_instances") self._mox.StubOutWithMock(vmutils.VMUtils, "get_vm_summary_info") self._mox.StubOutWithMock(vmutils.VMUtils, "take_vm_snapshot") self._mox.StubOutWithMock(vmutils.VMUtils, "remove_vm_snapshot") self._mox.StubOutWithMock(vmutils.VMUtils, "set_nic_connection") self._mox.StubOutWithMock(vmutils.VMUtils, "get_vm_scsi_controller") self._mox.StubOutWithMock(vmutils.VMUtils, "get_vm_ide_controller") self._mox.StubOutWithMock(vmutils.VMUtils, "get_attached_disks_count") self._mox.StubOutWithMock(vmutils.VMUtils, "attach_volume_to_controller") self._mox.StubOutWithMock(vmutils.VMUtils, "get_mounted_disk_by_drive_number") self._mox.StubOutWithMock(vmutils.VMUtils, "detach_vm_disk") self._mox.StubOutWithMock(vmutils.VMUtils, "get_vm_storage_paths") self._mox.StubOutWithMock(vmutils.VMUtils, "get_controller_volume_paths") self._mox.StubOutWithMock(vhdutils.VHDUtils, "create_differencing_vhd") self._mox.StubOutWithMock(vhdutils.VHDUtils, "reconnect_parent_vhd") self._mox.StubOutWithMock(vhdutils.VHDUtils, "merge_vhd") self._mox.StubOutWithMock(vhdutils.VHDUtils, "get_vhd_parent_path") self._mox.StubOutWithMock(vhdutils.VHDUtils, "get_vhd_info") self._mox.StubOutWithMock(vhdutils.VHDUtils, "resize_vhd") self._mox.StubOutWithMock(vhdutils.VHDUtils, "validate_vhd") self._mox.StubOutWithMock(hostutils.HostUtils, "get_cpus_info") self._mox.StubOutWithMock(hostutils.HostUtils, "is_cpu_feature_present") self._mox.StubOutWithMock(hostutils.HostUtils, "get_memory_info") self._mox.StubOutWithMock(hostutils.HostUtils, "get_volume_info") self._mox.StubOutWithMock(hostutils.HostUtils, "get_windows_version") self._mox.StubOutWithMock(hostutils.HostUtils, "get_local_ips") self._mox.StubOutWithMock(networkutils.NetworkUtils, "get_external_vswitch") self._mox.StubOutWithMock(networkutils.NetworkUtils, "create_vswitch_port") self._mox.StubOutWithMock(livemigrationutils.LiveMigrationUtils, "live_migrate_vm") self._mox.StubOutWithMock(livemigrationutils.LiveMigrationUtils, "check_live_migration_config") self._mox.StubOutWithMock(basevolumeutils.BaseVolumeUtils, "volume_in_mapping") self._mox.StubOutWithMock(basevolumeutils.BaseVolumeUtils, "get_session_id_from_mounted_disk") self._mox.StubOutWithMock(basevolumeutils.BaseVolumeUtils, "get_device_number_for_target") self._mox.StubOutWithMock(basevolumeutils.BaseVolumeUtils, "get_target_from_disk_path") self._mox.StubOutWithMock(volumeutils.VolumeUtils, "login_storage_target") self._mox.StubOutWithMock(volumeutils.VolumeUtils, "logout_storage_target") self._mox.StubOutWithMock(volumeutils.VolumeUtils, "execute_log_out") self._mox.StubOutWithMock(volumeutilsv2.VolumeUtilsV2, "login_storage_target") self._mox.StubOutWithMock(volumeutilsv2.VolumeUtilsV2, "logout_storage_target") self._mox.StubOutWithMock(volumeutilsv2.VolumeUtilsV2, "execute_log_out") self._mox.StubOutClassWithMocks(instance_metadata, "InstanceMetadata") self._mox.StubOutWithMock(instance_metadata.InstanceMetadata, "metadata_for_config_drive") # Can't use StubOutClassWithMocks due to __exit__ and __enter__ self._mox.StubOutWithMock(configdrive, "ConfigDriveBuilder") self._mox.StubOutWithMock(configdrive.ConfigDriveBuilder, "make_drive") self._mox.StubOutWithMock(utils, "execute")