Beispiel #1
0
    def test_cinder_default(self):
        fv = FakeVolume('creating', 'available')
        stack_name = 'test_volume_stack'

        clients.OpenStackClients.cinder().MultipleTimes().AndReturn(
            self.cinder_fc)
        vol_name = utils.PhysName(stack_name, 'DataVolume')
        self.cinder_fc.volumes.create(
            size=1, availability_zone='nova',
            display_description=None,
            display_name=vol_name).AndReturn(fv)

        self.m.ReplayAll()

        t = template_format.parse(volume_template)
        t['Resources']['DataVolume']['Properties'] = {
            'size': '1',
            'availability_zone': 'nova',
        }
        stack = utils.parse_stack(t, stack_name=stack_name)

        rsrc = vol.CinderVolume('DataVolume',
                                t['Resources']['DataVolume'],
                                stack)
        self.assertEqual(rsrc.validate(), None)
        scheduler.TaskRunner(rsrc.create)()
        self.assertEqual(rsrc.state, (rsrc.CREATE, rsrc.COMPLETE))
        self.assertEqual(fv.status, 'available')

        self.m.VerifyAll()
Beispiel #2
0
    def test_cinder_fn_getatt(self):
        fv = FakeVolume('creating',
                        'available',
                        availability_zone='zone1',
                        size=1,
                        snapshot_id='snap-123',
                        display_name='name',
                        display_description='desc',
                        volume_type='lvm',
                        metadata={'key': 'value'},
                        source_volid=None,
                        status='available',
                        bootable=False,
                        created_at='2013-02-25T02:40:21.000000')
        stack_name = 'test_volume_stack'

        clients.OpenStackClients.cinder().MultipleTimes().AndReturn(
            self.cinder_fc)
        vol_name = utils.PhysName(stack_name, 'DataVolume')
        self.cinder_fc.volumes.create(size=u'1',
                                      availability_zone='nova',
                                      display_description=None,
                                      display_name=vol_name).AndReturn(fv)

        self.cinder_fc.volumes.get('vol-123').MultipleTimes().AndReturn(fv)

        self.m.ReplayAll()

        t = template_format.parse(volume_template)
        t['Resources']['DataVolume']['Properties'] = {
            'size': '1',
            'availability_zone': 'nova',
        }
        stack = parse_stack(t, stack_name=stack_name)

        rsrc = vol.CinderVolume('DataVolume', t['Resources']['DataVolume'],
                                stack)
        scheduler.TaskRunner(rsrc.create)()
        self.assertEqual(u'vol-123', rsrc.FnGetAtt('id'))
        self.assertEqual(u'zone1', rsrc.FnGetAtt('availability_zone'))
        self.assertEqual(u'1', rsrc.FnGetAtt('size'))
        self.assertEqual(u'snap-123', rsrc.FnGetAtt('snapshot_id'))
        self.assertEqual(u'name', rsrc.FnGetAtt('display_name'))
        self.assertEqual(u'desc', rsrc.FnGetAtt('display_description'))
        self.assertEqual(u'lvm', rsrc.FnGetAtt('volume_type'))
        self.assertEqual(json.dumps({'key': 'value'}),
                         rsrc.FnGetAtt('metadata'))
        self.assertEqual(u'None', rsrc.FnGetAtt('source_volid'))
        self.assertEqual(u'available', rsrc.FnGetAtt('status'))
        self.assertEqual(u'2013-02-25T02:40:21.000000',
                         rsrc.FnGetAtt('created_at'))
        self.assertEqual(u'False', rsrc.FnGetAtt('bootable'))
        error = self.assertRaises(exception.InvalidTemplateAttribute,
                                  rsrc.FnGetAtt, 'unknown')
        self.assertEqual(
            'The Referenced Attribute (DataVolume unknown) is incorrect.',
            str(error))

        self.m.VerifyAll()
Beispiel #3
0
 def test_volume_size_constraint(self):
     t = template_format.parse(volume_template)
     t['Resources']['DataVolume']['Properties'] = {'size': '0'}
     stack = utils.parse_stack(t)
     rsrc = vol.CinderVolume('DataVolume', t['Resources']['DataVolume'],
                             stack)
     error = self.assertRaises(exception.StackValidationFailed,
                               rsrc.validate)
     self.assertEqual(
         "Property error : DataVolume: size 0 is out of "
         "range (min: 1, max: None)", str(error))
Beispiel #4
0
    def test_cinder_create(self):
        fv = FakeVolume('creating', 'available')
        stack_name = 'test_volume_stack'

        clients.OpenStackClients.cinder().MultipleTimes().AndReturn(
            self.cinder_fc)
        self.cinder_fc.volumes.create(
            size=u'1',
            availability_zone='nova',
            display_description='CustomDescription',
            display_name='CustomName',
            imageRef='46988116-6703-4623-9dbc-2bc6d284021b',
            snapshot_id='snap-123',
            metadata={
                'key': 'value'
            },
            source_volid='vol-012',
            volume_type='lvm').AndReturn(fv)

        self.m.ReplayAll()

        t = template_format.parse(volume_template)
        t['Resources']['DataVolume']['Properties'] = {
            'size': '1',
            'availability_zone': 'nova',
            'name': 'CustomName',
            'description': 'CustomDescription',
            'volume_type': 'lvm',
            'metadata': {
                'key': 'value'
            },
            # Note that specifying all these arguments doesn't work in
            # practice, as they are conflicting, but we just want to check they
            # are sent to the backend.
            'imageRef': '46988116-6703-4623-9dbc-2bc6d284021b',
            'snapshot_id': 'snap-123',
            'source_volid': 'vol-012',
        }
        stack = utils.parse_stack(t, stack_name=stack_name)

        rsrc = vol.CinderVolume('DataVolume', t['Resources']['DataVolume'],
                                stack)
        self.assertEqual(rsrc.validate(), None)
        scheduler.TaskRunner(rsrc.create)()
        self.assertEqual(rsrc.state, (rsrc.CREATE, rsrc.COMPLETE))
        self.assertEqual(fv.status, 'available')

        self.m.VerifyAll()
Beispiel #5
0
    def test_cinder_create_from_image(self):
        fv = FakeVolumeWithStateTransition('downloading', 'available')
        stack_name = 'test_volume_stack'
        image_id = '46988116-6703-4623-9dbc-2bc6d284021b'
        clients.OpenStackClients.cinder().MultipleTimes().AndReturn(
            self.cinder_fc)
        g_cli_mock = self.m.CreateMockAnything()
        self.m.StubOutWithMock(clients.OpenStackClients, 'glance')
        clients.OpenStackClients.glance().MultipleTimes().AndReturn(
            g_cli_mock)
        self.m.StubOutWithMock(glance_utils, 'get_image_id')
        glance_utils.get_image_id(g_cli_mock, image_id).MultipleTimes().\
            AndReturn(image_id)

        self.cinder_fc.volumes.create(
            size=1, availability_zone='nova',
            display_description='ImageVolumeDescription',
            display_name='ImageVolume',
            imageRef=image_id).AndReturn(fv)

        self.m.ReplayAll()

        t = template_format.parse(volume_template)
        t['Resources']['DataVolume']['Properties'] = {
            'size': '1',
            'name': 'ImageVolume',
            'description': 'ImageVolumeDescription',
            'availability_zone': 'nova',
            'image': image_id,
        }
        stack = utils.parse_stack(t, stack_name=stack_name)

        rsrc = vol.CinderVolume('DataVolume',
                                t['Resources']['DataVolume'],
                                stack)
        self.assertIsNone(rsrc.validate())
        scheduler.TaskRunner(rsrc.create)()
        self.assertEqual((rsrc.CREATE, rsrc.COMPLETE), rsrc.state)
        self.assertEqual('available', fv.status)

        self.m.VerifyAll()
Beispiel #6
0
    def test_cinder_create_from_image(self):
        fv = FakeVolumeWithStateTransition('downloading', 'available')
        stack_name = 'test_volume_stack'

        clients.OpenStackClients.cinder().MultipleTimes().AndReturn(
            self.cinder_fc)
        clients.OpenStackClients.nova('compute').AndReturn(self.fc)
        nova_utils.get_image_id(
            self.fc, '46988116-6703-4623-9dbc-2bc6d284021b').AndReturn(
                '46988116-6703-4623-9dbc-2bc6d284021b')
        self.cinder_fc.volumes.create(
            size=1, availability_zone='nova',
            display_description='ImageVolumeDescription',
            display_name='ImageVolume',
            imageRef='46988116-6703-4623-9dbc-2bc6d284021b').AndReturn(fv)

        self.m.ReplayAll()

        t = template_format.parse(volume_template)
        t['Resources']['DataVolume']['Properties'] = {
            'size': '1',
            'name': 'ImageVolume',
            'description': 'ImageVolumeDescription',
            'availability_zone': 'nova',
            'image': '46988116-6703-4623-9dbc-2bc6d284021b',
        }
        stack = utils.parse_stack(t, stack_name=stack_name)

        rsrc = vol.CinderVolume('DataVolume',
                                t['Resources']['DataVolume'],
                                stack)
        self.assertEqual(rsrc.validate(), None)
        scheduler.TaskRunner(rsrc.create)()
        self.assertEqual(rsrc.state, (rsrc.CREATE, rsrc.COMPLETE))
        self.assertEqual(fv.status, 'available')

        self.m.VerifyAll()