Example #1
0
    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)

        fake_network.fake_get_instance_nw_info(self.stubs, 1, 1,
                                               spectacular=True)

        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()
Example #2
0
 def test_power_on_already_running(self):
     self._instance_data = self._get_instance_data()
     network_info = fake_network.fake_get_instance_nw_info(self.stubs, spectacular=True)
     vmutils.VMUtils.set_vm_state(mox.Func(self._check_instance_name), constants.HYPERV_VM_STATE_ENABLED)
     self._mox.ReplayAll()
     self._conn.power_on(self._context, self._instance_data, network_info)
     self._mox.VerifyAll()
Example #3
0
    def test_finish_revert_migration(self):
        self._instance_data = self._get_instance_data()
        instance = db.instance_create(self._context, self._instance_data)
        network_info = fake_network.fake_get_instance_nw_info(self.stubs,
                                                              spectacular=True)

        fake_revert_path = ('C:\\FakeInstancesPath\\%s\\_revert' %
                            instance['name'])

        m = basevolumeutils.BaseVolumeUtils.volume_in_mapping(
            mox.IsA(str), None)
        m.AndReturn(False)

        m = fake.PathUtils.get_instance_dir(mox.IsA(str),
                                            create_dir=False,
                                            remove_dir=True)
        m.AndReturn(self._test_instance_dir)

        m = pathutils.PathUtils.get_instance_migr_revert_dir(instance['name'])
        m.AndReturn(fake_revert_path)
        fake.PathUtils.rename(fake_revert_path, mox.IsA(str))

        m = fake.PathUtils.get_instance_dir(mox.IsA(str))
        m.AndReturn(self._test_instance_dir)

        self._set_vm_name(instance['name'])
        self._setup_create_instance_mocks(None, False)

        vmutils.VMUtils.set_vm_state(mox.Func(self._check_instance_name),
                                     constants.HYPERV_VM_STATE_ENABLED)

        self._mox.ReplayAll()
        self._conn.finish_revert_migration(instance, network_info, None)
        self._mox.VerifyAll()
Example #4
0
    def _test_pre_live_migration(self, cow):
        self.flags(use_cow_images=cow)

        instance_data = self._get_instance_data()

        network_info = fake_network.fake_get_instance_nw_info(self.stubs,
                                                              spectacular=True)

        m = livemigrationutils.LiveMigrationUtils.check_live_migration_config()
        m.AndReturn(True)

        if cow:
            m = basevolumeutils.BaseVolumeUtils.volume_in_mapping(
                mox.IsA(str), None)
            m.AndReturn([])

        self._mox.ReplayAll()
        self._conn.pre_live_migration(self._context, instance_data, None,
                                      network_info)
        self._mox.VerifyAll()

        if cow:
            self.assertTrue(self._fetched_image is not None)
        else:
            self.assertTrue(self._fetched_image is None)
Example #5
0
    def setUp(self):
        super(NotificationsTestCase, self).setUp()

        self.net_info = fake_network.fake_get_instance_nw_info(self.stubs, 1, 1)

        def fake_get_nw_info(cls, ctxt, instance):
            self.assertTrue(ctxt.is_admin)
            return self.net_info

        self.stubs.Set(network_api.API, "get_instance_nw_info", fake_get_nw_info)
        fake_network.set_stub_network_methods(self.stubs)

        fake_notifier.stub_notifier(self.stubs)
        self.addCleanup(fake_notifier.reset)

        self.flags(
            compute_driver="nova.virt.fake.FakeDriver",
            network_manager="nova.network.manager.FlatManager",
            notify_on_state_change="vm_and_task_state",
            host="testhost",
        )

        self.user_id = "fake"
        self.project_id = "fake"
        self.context = context.RequestContext(self.user_id, self.project_id)

        self.instance = self._wrapped_create()
Example #6
0
    def setUp(self):
        super(NotificationsTestCase, self).setUp()

        self.net_info = fake_network.fake_get_instance_nw_info(
            self.stubs, 1, 1, spectacular=True)

        def fake_get_nw_info(cls, ctxt, instance):
            self.assertTrue(ctxt.is_admin)
            return self.net_info

        self.stubs.Set(network_api.API, 'get_instance_nw_info',
                       fake_get_nw_info)
        fake_network.set_stub_network_methods(self.stubs)

        self.flags(compute_driver='nova.virt.fake.FakeDriver',
                   notification_driver=[test_notifier.__name__],
                   network_manager='nova.network.manager.FlatManager',
                   notify_on_state_change="vm_and_task_state",
                   host='testhost')

        self.user_id = 'fake'
        self.project_id = 'fake'
        self.context = context.RequestContext(self.user_id, self.project_id)
        test_notifier.NOTIFICATIONS = []

        self.instance = self._wrapped_create()
Example #7
0
    def setUp(self):
        super(NotificationsTestCase, self).setUp()

        self.net_info = fake_network.fake_get_instance_nw_info(self.stubs, 1,
                                                        1, spectacular=True)

        def fake_get_nw_info(cls, ctxt, instance):
            self.assertTrue(ctxt.is_admin)
            return self.net_info

        self.stubs.Set(network_api.API, 'get_instance_nw_info',
                fake_get_nw_info)
        fake_network.set_stub_network_methods(self.stubs)

        self.flags(compute_driver='nova.virt.fake.FakeDriver',
                   notification_driver=[test_notifier.__name__],
                   network_manager='nova.network.manager.FlatManager',
                   notify_on_state_change="vm_and_task_state",
                   host='testhost')

        self.user_id = 'fake'
        self.project_id = 'fake'
        self.context = context.RequestContext(self.user_id, self.project_id)
        test_notifier.NOTIFICATIONS = []

        self.instance = self._wrapped_create()
Example #8
0
    def test_finish_revert_migration(self):
        self._instance_data = self._get_instance_data()
        instance = db.instance_create(self._context, self._instance_data)
        network_info = fake_network.fake_get_instance_nw_info(
            self.stubs, spectacular=True)

        fake_revert_path = ('C:\\FakeInstancesPath\\%s\\_revert' %
                            instance['name'])

        m = basevolumeutils.BaseVolumeUtils.volume_in_mapping(mox.IsA(str),
                                                              None)
        m.AndReturn(False)

        m = pathutils.PathUtils.get_instance_migr_revert_dir(instance['name'])
        m.AndReturn(fake_revert_path)
        fake.PathUtils.rename(fake_revert_path, mox.IsA(str))

        self._set_vm_name(instance['name'])
        self._setup_create_instance_mocks(None, False)

        vmutils.VMUtils.set_vm_state(mox.Func(self._check_instance_name),
                                     constants.HYPERV_VM_STATE_ENABLED)

        self._mox.ReplayAll()
        self._conn.finish_revert_migration(instance, network_info, None)
        self._mox.VerifyAll()
Example #9
0
    def _test_pre_live_migration(self, cow):
        self.flags(use_cow_images=cow)

        instance_data = self._get_instance_data()

        network_info = fake_network.fake_get_instance_nw_info(self.stubs,
                                                              spectacular=True)

        m = livemigrationutils.LiveMigrationUtils.check_live_migration_config()
        m.AndReturn(True)

        if cow:
            m = basevolumeutils.BaseVolumeUtils.volume_in_mapping(mox.IsA(str),
                                                                  None)
            m.AndReturn(False)

            vhdutils.VHDUtils.get_vhd_info(mox.Func(self._check_img_path))

        self._mox.ReplayAll()
        self._conn.pre_live_migration(self._context, instance_data,
                                      None, network_info)
        self._mox.VerifyAll()

        if cow:
            self.assertTrue(self._fetched_image is not None)
        else:
            self.assertTrue(self._fetched_image is None)
    def _test_pre_live_migration(self, cow):
        self.flags(use_cow_images=cow)

        instance_data = self._get_instance_data()
        instance = db.instance_create(self._context, instance_data)
        instance['system_metadata'] = {}

        network_info = fake_network.fake_get_instance_nw_info(self.stubs,
                                                              spectacular=True)

        m = livemigrationutils.LiveMigrationUtils.check_live_migration_config()
        m.AndReturn(True)

        if cow:
            m = basevolumeutils.BaseVolumeUtils.volume_in_mapping(
                mox.IsA(str), None)
            m.AndReturn(False)

            m = vhdutils.VHDUtils.get_vhd_info(mox.Func(self._check_img_path))
            m.AndReturn({'MaxInternalSize': 1024})

            fake.PathUtils.copyfile(mox.IsA(str), mox.IsA(str))
            vhdutils.VHDUtils.resize_vhd(mox.IsA(str), mox.IsA(object))

        self._mox.ReplayAll()
        self._conn.pre_live_migration(self._context, instance, None,
                                      network_info)
        self._mox.VerifyAll()

        if cow:
            self.assertTrue(self._fetched_image is not None)
        else:
            self.assertTrue(self._fetched_image is None)
Example #11
0
    def _test_pre_live_migration(self, cow):
        self.flags(use_cow_images=cow)

        instance_data = self._get_instance_data()
        instance = db.instance_create(self._context, instance_data)
        instance['system_metadata'] = {}

        network_info = fake_network.fake_get_instance_nw_info(self.stubs,
                                                              spectacular=True)

        m = livemigrationutils.LiveMigrationUtils.check_live_migration_config()
        m.AndReturn(True)

        if cow:
            m = basevolumeutils.BaseVolumeUtils.volume_in_mapping(mox.IsA(str),
                                                                  None)
            m.AndReturn(False)

            m = vhdutils.VHDUtils.get_vhd_info(mox.Func(self._check_img_path))
            m.AndReturn({'MaxInternalSize': 1024})

            fake.PathUtils.copyfile(mox.IsA(str), mox.IsA(str))
            vhdutils.VHDUtils.resize_vhd(mox.IsA(str), mox.IsA(object))

        self._mox.ReplayAll()
        self._conn.pre_live_migration(self._context, instance,
                                      None, network_info)
        self._mox.VerifyAll()

        if cow:
            self.assertTrue(self._fetched_image is not None)
        else:
            self.assertTrue(self._fetched_image is None)
Example #12
0
    def _setup_test_migrate_disk_and_power_off_mocks(self,
                                                     same_host=False,
                                                     with_exception=False):
        self._instance_data = self._get_instance_data()
        instance = db.instance_create(self._context, self._instance_data)
        network_info = fake_network.fake_get_instance_nw_info(self.stubs,
                                                              spectacular=True)

        fake_local_ip = '10.0.0.1'
        if same_host:
            fake_dest_ip = fake_local_ip
        else:
            fake_dest_ip = '10.0.0.2'

        fake_root_vhd_path = 'C:\\FakePath\\root.vhd'
        fake_revert_path = os.path.join(self._test_instance_dir, '_revert')

        func = mox.Func(self._check_instance_name)
        vmutils.VMUtils.set_vm_state(func, constants.HYPERV_VM_STATE_DISABLED)

        m = vmutils.VMUtils.get_vm_storage_paths(func)
        m.AndReturn(([fake_root_vhd_path], []))

        m = hostutils.HostUtils.get_local_ips()
        m.AndReturn([fake_local_ip])

        m = fake.PathUtils.get_instance_dir(mox.IsA(str))
        m.AndReturn(self._test_instance_dir)

        m = pathutils.PathUtils.get_instance_migr_revert_dir(instance['name'],
                                                             remove_dir=True)
        m.AndReturn(fake_revert_path)

        if same_host:
            fake.PathUtils.makedirs(mox.IsA(str))

        m = fake.PathUtils.copy(fake_root_vhd_path, mox.IsA(str))
        if with_exception:
            m.AndRaise(shutil.Error('Simulated copy error'))
            m = fake.PathUtils.get_instance_dir(mox.IsA(str),
                                                mox.IsA(str),
                                                remove_dir=True)
            m.AndReturn(self._test_instance_dir)
        else:
            fake.PathUtils.rename(mox.IsA(str), mox.IsA(str))
            destroy_disks = True
            if same_host:
                fake.PathUtils.rename(mox.IsA(str), mox.IsA(str))
                destroy_disks = False

            self._setup_destroy_mocks(False)

            if destroy_disks:
                m = fake.PathUtils.get_instance_dir(mox.IsA(str),
                                                    mox.IsA(str),
                                                    remove_dir=True)
                m.AndReturn(self._test_instance_dir)

        return (instance, fake_dest_ip, network_info)
Example #13
0
    def test_reboot(self):
        self._spawn_instance(True)

        network_info = fake_network.fake_get_instance_nw_info(self.stubs, spectacular=True)
        self._conn.reboot(self._instance_data, network_info, None)

        vmstate = self._hypervutils.get_vm_state(self._instance_data["name"])
        self.assertEquals(vmstate, constants.HYPERV_VM_STATE_ENABLED)
Example #14
0
 def test_local_ipv4_from_address(self):
     nw_info = fake_network.fake_get_instance_nw_info(self.stubs,
                                                      num_networks=2)
     expected_local = "fake"
     md = fake_InstanceMetadata(self.stubs, self.instance,
                                network_info=nw_info, address="fake")
     data = md.get_ec2_metadata(version='2009-04-04')
     self.assertEqual(data['meta-data']['local-ipv4'], expected_local)
Example #15
0
 def test_local_ipv4_from_address(self):
     nw_info = fake_network.fake_get_instance_nw_info(self.stubs,
                                                      num_networks=2)
     expected_local = "fake"
     md = fake_InstanceMetadata(self.stubs, self.instance,
                                network_info=nw_info, address="fake")
     data = md.get_ec2_metadata(version='2009-04-04')
     self.assertEqual(data['meta-data']['local-ipv4'], expected_local)
Example #16
0
    def _setup_test_migrate_disk_and_power_off_mocks(self, same_host=False,
                                                     with_exception=False):
        self._instance_data = self._get_instance_data()
        instance = db.instance_create(self._context, self._instance_data)
        network_info = fake_network.fake_get_instance_nw_info(
            self.stubs, spectacular=True)

        fake_local_ip = '10.0.0.1'
        if same_host:
            fake_dest_ip = fake_local_ip
        else:
            fake_dest_ip = '10.0.0.2'

        fake_root_vhd_path = 'C:\\FakePath\\root.vhd'
        fake_revert_path = os.path.join(self._test_instance_dir, '_revert')

        func = mox.Func(self._check_instance_name)
        vmutils.VMUtils.set_vm_state(func, constants.HYPERV_VM_STATE_DISABLED)

        m = vmutils.VMUtils.get_vm_storage_paths(func)
        m.AndReturn(([fake_root_vhd_path], []))

        m = hostutils.HostUtils.get_local_ips()
        m.AndReturn([fake_local_ip])

        m = fake.PathUtils.get_instance_dir(mox.IsA(str))
        m.AndReturn(self._test_instance_dir)

        m = pathutils.PathUtils.get_instance_migr_revert_dir(instance['name'],
                                                             remove_dir=True)
        m.AndReturn(fake_revert_path)

        if same_host:
            fake.PathUtils.makedirs(mox.IsA(str))

        m = fake.PathUtils.copy(fake_root_vhd_path, mox.IsA(str))
        if with_exception:
            m.AndRaise(shutil.Error('Simulated copy error'))
            m = fake.PathUtils.get_instance_dir(mox.IsA(str),
                                                mox.IsA(str),
                                                remove_dir=True)
            m.AndReturn(self._test_instance_dir)
        else:
            fake.PathUtils.rename(mox.IsA(str), mox.IsA(str))
            destroy_disks = True
            if same_host:
                fake.PathUtils.rename(mox.IsA(str), mox.IsA(str))
                destroy_disks = False

            self._setup_destroy_mocks(False)

            if destroy_disks:
                m = fake.PathUtils.get_instance_dir(mox.IsA(str),
                                                    mox.IsA(str),
                                                    remove_dir=True)
                m.AndReturn(self._test_instance_dir)

        return (instance, fake_dest_ip, network_info)
Example #17
0
    def test_reboot(self):
        self._spawn_instance(True)

        network_info = fake_network.fake_get_instance_nw_info(self.stubs,
                                                              spectacular=True)
        self._conn.reboot(self._instance_data, network_info, None)

        vmstate = self._hypervutils.get_vm_state(self._instance_data["name"])
        self.assertEquals(vmstate, constants.HYPERV_VM_STATE_ENABLED)
Example #18
0
    def test_confirm_migration(self):
        self._instance_data = self._get_instance_data()
        instance = db.instance_create(self._context, self._instance_data)
        network_info = fake_network.fake_get_instance_nw_info(self.stubs, spectacular=True)

        pathutils.PathUtils.get_instance_migr_revert_dir(instance["name"], remove_dir=True)
        self._mox.ReplayAll()
        self._conn.confirm_migration(None, instance, network_info)
        self._mox.VerifyAll()
Example #19
0
    def test_reboot(self):

        network_info = fake_network.fake_get_instance_nw_info(self.stubs, spectacular=True)
        self._instance_data = self._get_instance_data()

        vmutils.VMUtils.set_vm_state(mox.Func(self._check_instance_name), constants.HYPERV_VM_STATE_REBOOT)

        self._mox.ReplayAll()
        self._conn.reboot(self._context, self._instance_data, network_info, None)
        self._mox.VerifyAll()
Example #20
0
    def test_confirm_migration(self):
        self._instance_data = self._get_instance_data()
        instance = db.instance_create(self._context, self._instance_data)
        network_info = fake_network.fake_get_instance_nw_info(self.stubs,
                                                              spectacular=True)

        pathutils.PathUtils.get_instance_migr_revert_dir(instance['name'],
                                                         remove_dir=True)
        self._mox.ReplayAll()
        self._conn.confirm_migration(None, instance, network_info)
        self._mox.VerifyAll()
Example #21
0
    def _test_pre_live_migration(self, cow, with_volumes):
        self.flags(use_cow_images=cow)

        instance_data = self._get_instance_data()
        instance = db.instance_create(self._context, instance_data)
        instance['system_metadata'] = {}

        network_info = fake_network.fake_get_instance_nw_info(self.stubs,
                                                              spectacular=True)

        m = livemigrationutils.LiveMigrationUtils.check_live_migration_config()
        m.AndReturn(True)

        if cow:
            m = basevolumeutils.BaseVolumeUtils.volume_in_mapping(mox.IsA(str),
                                                                  None)
            m.AndReturn(False)

            m = vhdutils.VHDUtils.get_vhd_info(mox.Func(self._check_img_path))
            m.AndReturn({'MaxInternalSize': 1024})

            fake.PathUtils.copyfile(mox.IsA(str), mox.IsA(str))
            vhdutils.VHDUtils.resize_vhd(mox.IsA(str), mox.IsA(object))

        if with_volumes:
            block_device_info = db_fakes.get_fake_block_device_info(
                self._volume_target_portal, self._volume_id)

            mapping = driver.block_device_info_get_mapping(block_device_info)
            data = mapping[0]['connection_info']['data']
            target_lun = data['target_lun']
            target_iqn = data['target_iqn']
            target_portal = data['target_portal']

            fake_mounted_disk = "fake_mounted_disk"
            fake_device_number = 0

            self._mock_login_storage_target(target_iqn, target_lun,
                                            target_portal,
                                            fake_mounted_disk,
                                            fake_device_number)
        else:
            block_device_info = None

        self._mox.ReplayAll()
        self._conn.pre_live_migration(self._context, instance,
                                      block_device_info, network_info)
        self._mox.VerifyAll()

        if cow:
            self.assertTrue(self._fetched_image is not None)
        else:
            self.assertTrue(self._fetched_image is None)
Example #22
0
    def _test_pre_live_migration(self, cow, with_volumes):
        self.flags(use_cow_images=cow)

        instance_data = self._get_instance_data()
        instance = db.instance_create(self._context, instance_data)
        instance['system_metadata'] = {}

        network_info = fake_network.fake_get_instance_nw_info(self.stubs,
                                                              spectacular=True)

        m = livemigrationutils.LiveMigrationUtils.check_live_migration_config()
        m.AndReturn(True)

        if cow:
            m = basevolumeutils.BaseVolumeUtils.volume_in_mapping(mox.IsA(str),
                                                                  None)
            m.AndReturn(False)

            m = vhdutils.VHDUtils.get_vhd_info(mox.Func(self._check_img_path))
            m.AndReturn({'MaxInternalSize': 1024})

            fake.PathUtils.copyfile(mox.IsA(str), mox.IsA(str))
            vhdutils.VHDUtils.resize_vhd(mox.IsA(str), mox.IsA(object))

        if with_volumes:
            block_device_info = db_fakes.get_fake_block_device_info(
                self._volume_target_portal, self._volume_id)

            mapping = driver.block_device_info_get_mapping(block_device_info)
            data = mapping[0]['connection_info']['data']
            target_lun = data['target_lun']
            target_iqn = data['target_iqn']
            target_portal = data['target_portal']

            fake_mounted_disk = "fake_mounted_disk"
            fake_device_number = 0

            self._mock_login_storage_target(target_iqn, target_lun,
                                            target_portal,
                                            fake_mounted_disk,
                                            fake_device_number)
        else:
            block_device_info = None

        self._mox.ReplayAll()
        self._conn.pre_live_migration(self._context, instance,
                                      block_device_info, network_info)
        self._mox.VerifyAll()

        if cow:
            self.assertTrue(self._fetched_image is not None)
        else:
            self.assertTrue(self._fetched_image is None)
Example #23
0
    def test_reboot(self):

        network_info = fake_network.fake_get_instance_nw_info(self.stubs,
                                                              spectacular=True)
        self._instance_data = self._get_instance_data()

        vmutils.VMUtils.set_vm_state(mox.Func(self._check_instance_name),
                                     constants.HYPERV_VM_STATE_REBOOT)

        self._mox.ReplayAll()
        self._conn.reboot(self._context, self._instance_data, network_info,
                          None)
        self._mox.VerifyAll()
Example #24
0
    def _test_pre_live_migration(self, cow):
        self.flags(use_cow_images=cow)

        instance_name = "openstack_unit_test_vm_" + str(uuid.uuid4())

        network_info = fake_network.fake_get_instance_nw_info(self.stubs, spectacular=True)
        instance_data = db_fakes.get_fake_instance_data(instance_name, self._project_id, self._user_id)
        block_device_info = None

        self._conn.pre_live_migration(self._context, instance_data, block_device_info, network_info)

        if cow:
            self.assertTrue(not self._fetched_image is None)
        else:
            self.assertTrue(self._fetched_image is None)
Example #25
0
    def _spawn_instance(self, cow, block_device_info=None):
        self.flags(use_cow_images=cow)

        self._instance_data = self._get_instance_data()
        instance = db.instance_create(self._context, self._instance_data)

        image = db_fakes.get_fake_image_data(self._project_id, self._user_id)

        network_info = fake_network.fake_get_instance_nw_info(self.stubs,
                                                              spectacular=True)

        self._conn.spawn(self._context, instance, image,
                         injected_files=[], admin_password=None,
                         network_info=network_info,
                         block_device_info=block_device_info)
Example #26
0
    def _spawn_instance(self, cow, block_device_info=None):
        self.flags(use_cow_images=cow)

        instance_name = 'openstack_unit_test_vm_' + str(uuid.uuid4())

        self._instance_data = db_fakes.get_fake_instance_data(instance_name,
                self._project_id, self._user_id)
        instance = db.instance_create(self._context, self._instance_data)

        image = db_fakes.get_fake_image_data(self._project_id, self._user_id)

        network_info = fake_network.fake_get_instance_nw_info(self.stubs,
                                                              spectacular=True)

        self._conn.spawn(self._context, instance, image, network_info,
            block_device_info)
Example #27
0
    def _spawn_instance(self, cow, block_device_info=None):
        self.flags(use_cow_images=cow)

        self._instance_data = self._get_instance_data()
        instance = db.instance_create(self._context, self._instance_data)
        instance['system_metadata'] = {}

        image = db_fakes.get_fake_image_data(self._project_id, self._user_id)

        network_info = fake_network.fake_get_instance_nw_info(self.stubs,
                                                              spectacular=True)

        self._conn.spawn(self._context, instance, image,
                         injected_files=[], admin_password=None,
                         network_info=network_info,
                         block_device_info=block_device_info)
Example #28
0
    def test_finish_migration(self):
        self._instance_data = self._get_instance_data()
        instance = db.instance_create(self._context, self._instance_data)
        instance['system_metadata'] = {}
        network_info = fake_network.fake_get_instance_nw_info(
            self.stubs, spectacular=True)

        m = basevolumeutils.BaseVolumeUtils.volume_in_mapping(mox.IsA(str),
                                                              None)
        m.AndReturn(False)

        m = fake.PathUtils.get_instance_dir(mox.IsA(str))
        m.AndReturn(self._test_instance_dir)

        self._mox.StubOutWithMock(fake.PathUtils, 'exists')
        m = fake.PathUtils.exists(mox.IsA(str))
        m.AndReturn(True)

        fake_parent_vhd_path = (os.path.join('FakeParentPath', '%s.vhd' %
                                instance["image_ref"]))

        m = vhdutils.VHDUtils.get_vhd_info(mox.IsA(str))
        m.AndReturn({'ParentPath': fake_parent_vhd_path,
                     'MaxInternalSize': 1})

        m = fake.PathUtils.exists(mox.IsA(str))
        m.AndReturn(True)

        vhdutils.VHDUtils.reconnect_parent_vhd(mox.IsA(str), mox.IsA(str))

        m = vhdutils.VHDUtils.get_vhd_info(mox.IsA(str))
        m.AndReturn({'MaxInternalSize': 1024})

        m = fake.PathUtils.exists(mox.IsA(str))
        m.AndReturn(True)

        self._set_vm_name(instance['name'])
        self._setup_create_instance_mocks(None, False)

        vmutils.VMUtils.set_vm_state(mox.Func(self._check_instance_name),
                                     constants.HYPERV_VM_STATE_ENABLED)

        self._mox.ReplayAll()
        self._conn.finish_migration(self._context, None, instance, "",
                                    network_info, None, False, None)
        self._mox.VerifyAll()
Example #29
0
    def _spawn_instance(self, cow, block_device_info=None):
        self.flags(use_cow_images=cow)

        instance_name = 'openstack_unit_test_vm_' + str(uuid.uuid4())

        self._instance_data = db_fakes.get_fake_instance_data(instance_name,
                self._project_id, self._user_id)
        instance = db.instance_create(self._context, self._instance_data)

        image = db_fakes.get_fake_image_data(self._project_id, self._user_id)

        network_info = fake_network.fake_get_instance_nw_info(self.stubs,
                                                              spectacular=True)

        self._conn.spawn(self._context, instance, image,
                         injected_files=[], admin_password=None,
                         network_info=network_info,
                         block_device_info=block_device_info)
Example #30
0
    def _test_pre_live_migration(self, cow):
        self.flags(use_cow_images=cow)

        instance_name = 'openstack_unit_test_vm_' + str(uuid.uuid4())

        network_info = fake_network.fake_get_instance_nw_info(self.stubs,
                                                              spectacular=True)
        instance_data = db_fakes.get_fake_instance_data(
            instance_name, self._project_id, self._user_id)
        block_device_info = None

        self._conn.pre_live_migration(self._context, instance_data,
                                      block_device_info, network_info)

        if cow:
            self.assertTrue(not self._fetched_image is None)
        else:
            self.assertTrue(self._fetched_image is None)
Example #31
0
 def get_nw_info_for_instance(instance):
     return fake_network.fake_get_instance_nw_info(stubs, spectacular=True)
Example #32
0
 def fake_get_nw_info(cls, ctxt, instance):
     self.assertTrue(ctxt.is_admin)
     return fake_network.fake_get_instance_nw_info(self.stubs, 1, 1)
Example #33
0
 def test_local_ipv4_from_nw_info(self):
     nw_info = fake_network.fake_get_instance_nw_info(self.stubs, num_networks=2)
     expected_local = "192.168.1.100"
     md = fake_InstanceMetadata(self.stubs, self.instance, network_info=nw_info)
     data = md.get_ec2_metadata(version="2009-04-04")
     self.assertEqual(data["meta-data"]["local-ipv4"], expected_local)
Example #34
0
 def get_nw_info_for_instance(instance):
     return fake_network.fake_get_instance_nw_info(stubs, spectacular=True)
Example #35
0
 def common_get_nw_info_for_instance(context, instance):
     return fake_network.fake_get_instance_nw_info(self.stubs,
                                                   spectacular=True)
Example #36
0
    def _setup_test_migrate_disk_and_power_off_mocks(self, same_host=False, copy_exception=False, size_exception=False):
        self._instance_data = self._get_instance_data()
        instance = db.instance_create(self._context, self._instance_data)
        network_info = fake_network.fake_get_instance_nw_info(self.stubs, spectacular=True)

        instance["root_gb"] = 10

        fake_local_ip = "10.0.0.1"
        if same_host:
            fake_dest_ip = fake_local_ip
        else:
            fake_dest_ip = "10.0.0.2"

        if size_exception:
            flavor = "m1.tiny"
        else:
            flavor = "m1.small"

        instance_type = db.flavor_get_by_name(self._context, flavor)

        if not size_exception:
            fake_root_vhd_path = "C:\\FakePath\\root.vhd"
            fake_revert_path = os.path.join(self._test_instance_dir, "_revert")

            func = mox.Func(self._check_instance_name)
            vmutils.VMUtils.set_vm_state(func, constants.HYPERV_VM_STATE_DISABLED)

            m = vmutils.VMUtils.get_vm_storage_paths(func)
            m.AndReturn(([fake_root_vhd_path], []))

            m = hostutils.HostUtils.get_local_ips()
            m.AndReturn([fake_local_ip])

            m = fake.PathUtils.get_instance_dir(mox.IsA(str))
            m.AndReturn(self._test_instance_dir)

            m = pathutils.PathUtils.get_instance_migr_revert_dir(instance["name"], remove_dir=True)
            m.AndReturn(fake_revert_path)

            if same_host:
                fake.PathUtils.makedirs(mox.IsA(str))

            m = fake.PathUtils.copy(fake_root_vhd_path, mox.IsA(str))
            if copy_exception:
                m.AndRaise(shutil.Error("Simulated copy error"))
                m = fake.PathUtils.get_instance_dir(mox.IsA(str), mox.IsA(str), remove_dir=True)
                m.AndReturn(self._test_instance_dir)
            else:
                fake.PathUtils.rename(mox.IsA(str), mox.IsA(str))
                destroy_disks = True
                if same_host:
                    fake.PathUtils.rename(mox.IsA(str), mox.IsA(str))
                    destroy_disks = False

                self._setup_destroy_mocks(False)

                if destroy_disks:
                    m = fake.PathUtils.get_instance_dir(mox.IsA(str), mox.IsA(str), remove_dir=True)
                    m.AndReturn(self._test_instance_dir)

        return (instance, fake_dest_ip, network_info, instance_type)
Example #37
0
 def get_nw_info_for_instance(instance):
     return fake_network.fake_get_instance_nw_info(stubs)
Example #38
0
 def get_nw_info_for_instance(instance):
     return fake_network.fake_get_instance_nw_info(stubs)
Example #39
0
 def common_get_nw_info_for_instance(context, instance):
     return fake_network.fake_get_instance_nw_info(self.stubs,
                                                   spectacular=True)