Example #1
0
    def test_create_vdi(self):
        # Some images are registered with XenServer explicitly by calling
        # `create_vdi`
        vm_utils.create_vdi(self.session, "sr_ref", self.fake_instance, "myvdi", "root", 1024, read_only=True)

        expected = {"nova_disk_type": "root", "nova_instance_uuid": "aaaa-bbbb-cccc-dddd"}

        self.assertEqual(expected, self.session.args[0]["other_config"])
Example #2
0
    def test_no_admin_pass(self):
        # This is here to avoid masking errors, it shouldn't be used normally
        self.useFixture(fixtures.MonkeyPatch("nova.virt.xenapi.vm_utils.destroy_vdi", _fake_noop))

        # Mocks
        instance = {}

        self.mox.StubOutWithMock(vm_utils, "safe_find_sr")
        vm_utils.safe_find_sr("session").AndReturn("sr_ref")

        self.mox.StubOutWithMock(vm_utils, "create_vdi")
        vm_utils.create_vdi("session", "sr_ref", instance, "config-2", "configdrive", 64 * 1024 * 1024).AndReturn(
            "vdi_ref"
        )

        self.mox.StubOutWithMock(vm_utils, "vdi_attached_here")
        vm_utils.vdi_attached_here("session", "vdi_ref", read_only=False).AndReturn(contextified("mounted_dev"))

        class FakeInstanceMetadata(object):
            def __init__(self, instance, content=None, extra_md=None):
                pass

            def metadata_for_config_drive(self):
                return []

        self.useFixture(fixtures.MonkeyPatch("nova.api.metadata.base.InstanceMetadata", FakeInstanceMetadata))

        self.mox.StubOutWithMock(utils, "execute")
        utils.execute(
            "genisoimage",
            "-o",
            mox.IgnoreArg(),
            "-ldots",
            "-allow-lowercase",
            "-allow-multidot",
            "-l",
            "-publisher",
            mox.IgnoreArg(),
            "-quiet",
            "-J",
            "-r",
            "-V",
            "config-2",
            mox.IgnoreArg(),
            attempts=1,
            run_as_root=False,
        ).AndReturn(None)
        utils.execute("dd", mox.IgnoreArg(), mox.IgnoreArg(), run_as_root=True).AndReturn(None)

        self.mox.StubOutWithMock(vm_utils, "create_vbd")
        vm_utils.create_vbd("session", "vm_ref", "vdi_ref", mox.IgnoreArg(), bootable=False, read_only=True).AndReturn(
            None
        )

        self.mox.ReplayAll()

        # And the actual call we're testing
        vm_utils.generate_configdrive("session", instance, "vm_ref", "userdevice")
Example #3
0
    def test_create_vdi(self):
        # Some images are registered with XenServer explicitly by calling
        # `create_vdi`
        vm_utils.create_vdi(self.session, 'sr_ref', self.fake_instance,
                            'myvdi', 'root', 1024, read_only=True)

        expected = {'nova_disk_type': 'root',
                    'nova_instance_uuid': 'aaaa-bbbb-cccc-dddd'}

        self.assertEqual(expected, self.session.args[0]['other_config'])
Example #4
0
    def test_create_vdi(self):
        # Some images are registered with XenServer explicitly by calling
        # `create_vdi`
        vm_utils.create_vdi(self.session, 'sr_ref', self.fake_instance,
                            'myvdi', 'root', 1024, read_only=True)

        expected = {'nova_disk_type': 'root',
                    'nova_instance_uuid': 'aaaa-bbbb-cccc-dddd'}

        self.assertEqual(expected, self.session.args[0]['other_config'])
Example #5
0
    def test_no_admin_pass(self):
        # This is here to avoid masking errors, it shouldn't be used normally
        self.useFixture(fixtures.MonkeyPatch(
                'nova.virt.xenapi.vm_utils.destroy_vdi', _fake_noop))

        # Mocks
        instance = {}

        self.mox.StubOutWithMock(vm_utils, 'safe_find_sr')
        vm_utils.safe_find_sr('session').AndReturn('sr_ref')

        self.mox.StubOutWithMock(vm_utils, 'create_vdi')
        vm_utils.create_vdi('session', 'sr_ref', instance, 'config-2',
                            'configdrive',
                            64 * 1024 * 1024).AndReturn('vdi_ref')

        self.mox.StubOutWithMock(vm_utils, 'vdi_attached_here')
        vm_utils.vdi_attached_here(
            'session', 'vdi_ref', read_only=False).AndReturn(
                contextified('mounted_dev'))

        class FakeInstanceMetadata(object):
            def __init__(self, instance, content=None, extra_md=None):
                pass

            def metadata_for_config_drive(self):
                return []

        self.useFixture(fixtures.MonkeyPatch(
                'nova.api.metadata.base.InstanceMetadata',
                FakeInstanceMetadata))

        self.mox.StubOutWithMock(utils, 'execute')
        utils.execute('genisoimage', '-o', mox.IgnoreArg(), '-ldots',
                      '-allow-lowercase', '-allow-multidot', '-l',
                      '-publisher', mox.IgnoreArg(), '-quiet',
                      '-J', '-r', '-V', 'config-2', mox.IgnoreArg(),
                      attempts=1, run_as_root=False).AndReturn(None)
        utils.execute('dd', mox.IgnoreArg(), mox.IgnoreArg(),
                      run_as_root=True).AndReturn(None)

        self.mox.StubOutWithMock(vm_utils, 'create_vbd')
        vm_utils.create_vbd('session', 'vm_ref', 'vdi_ref', mox.IgnoreArg(),
                            bootable=False, read_only=True).AndReturn(None)

        self.mox.ReplayAll()

        # And the actual call we're testing
        vm_utils.generate_configdrive('session', instance, 'vm_ref',
                                      'userdevice')
Example #6
0
    def test_no_admin_pass(self):
        # This is here to avoid masking errors, it shouldn't be used normally
        self.useFixture(fixtures.MonkeyPatch(
                'nova.virt.xenapi.vm_utils.destroy_vdi', _fake_noop))

        # Mocks
        instance = {}

        self.mox.StubOutWithMock(vm_utils, 'safe_find_sr')
        vm_utils.safe_find_sr('session').AndReturn('sr_ref')

        self.mox.StubOutWithMock(vm_utils, 'create_vdi')
        vm_utils.create_vdi('session', 'sr_ref', instance, 'config-2',
                            'configdrive',
                            64 * 1024 * 1024).AndReturn('vdi_ref')

        self.mox.StubOutWithMock(vm_utils, 'vdi_attached_here')
        vm_utils.vdi_attached_here(
            'session', 'vdi_ref', read_only=False).AndReturn(
                contextified('mounted_dev'))

        class FakeInstanceMetadata(object):
            def __init__(self, instance, content=None, extra_md=None):
                pass

            def metadata_for_config_drive(self):
                return []

        self.useFixture(fixtures.MonkeyPatch(
                'nova.api.metadata.base.InstanceMetadata',
                FakeInstanceMetadata))

        self.mox.StubOutWithMock(utils, 'execute')
        utils.execute('genisoimage', '-o', mox.IgnoreArg(), '-ldots',
                      '-allow-lowercase', '-allow-multidot', '-l',
                      '-publisher', mox.IgnoreArg(), '-quiet',
                      '-J', '-r', '-V', 'config-2', mox.IgnoreArg(),
                      attempts=1, run_as_root=False).AndReturn(None)
        utils.execute('dd', mox.IgnoreArg(), mox.IgnoreArg(),
                      run_as_root=True).AndReturn(None)

        self.mox.StubOutWithMock(vm_utils, 'create_vbd')
        vm_utils.create_vbd('session', 'vm_ref', 'vdi_ref', mox.IgnoreArg(),
                            bootable=False, read_only=True).AndReturn(None)

        self.mox.ReplayAll()

        # And the actual call we're testing
        vm_utils.generate_configdrive('session', instance, 'vm_ref',
                                      'userdevice')
Example #7
0
class VolumeOps(object):
    """
    Management class for Volume-related tasks
    """
    def __init__(self, session):
        self._session = session

    def create_volume_for_sm(self, volume, sr_uuid):
        LOG.debug("Creating volume for Storage Manager")

        sm_vol_rec = {}
        try:
            sr_ref = self._session.call_xenapi("SR.get_by_uuid", sr_uuid)
        except self._session.XenAPI.Failure, exc:
            LOG.exception(exc)
            raise volume_utils.StorageError(_('Unable to get SR using uuid'))
        #Create VDI
        label = 'vol-' + volume['id']
        desc = 'xensm volume for ' + volume['id']
        # size presented to xenapi is in bytes, while euca api is in GB
        vdi_size = volume['size'] * 1024 * 1024 * 1024
        vdi_ref = vm_utils.create_vdi(self._session, sr_ref, None, label, desc,
                                      vdi_size, False)
        vdi_rec = self._session.call_xenapi("VDI.get_record", vdi_ref)
        sm_vol_rec['vdi_uuid'] = vdi_rec['uuid']
        return sm_vol_rec