コード例 #1
0
ファイル: nova_utils_tests.py プロジェクト: opnfv/snaps
    def setUp(self):
        """
        Setup objects required by VM instances
        :return:
        """

        guid = self.__class__.__name__ + '-' + str(uuid.uuid4())

        self.nova = nova_utils.nova_client(self.os_creds, self.os_session)
        self.cinder = cinder_utils.cinder_client(
            self.os_creds, self.os_session)

        self.image_creator = None
        self.network_creator = None
        self.flavor_creator = None
        self.volume_creator = None
        self.instance_creator = None

        try:
            image_settings = openstack_tests.cirros_image_settings(
                name=guid + '-image', image_metadata=self.image_metadata)
            self.image_creator = OpenStackImage(
                self.os_creds, image_settings=image_settings)
            self.image_creator.create()

            network_settings = openstack_tests.get_priv_net_config(
                project_name=self.os_creds.project_name,
                net_name="{}-{}".format(guid, 'net'),
                subnet_name="{}-{}".format(guid, 'subnet')).network_settings

            self.network_creator = OpenStackNetwork(
                self.os_creds, network_settings)
            self.network_creator.create()

            flavor_settings = openstack_tests.get_flavor_config(
                name=guid + '-flavor', ram=256, disk=10, vcpus=1,
                metadata=self.flavor_metadata)
            self.flavor_creator = OpenStackFlavor(
                self.os_creds, flavor_settings)
            self.flavor_creator.create()

            # Create Volume
            volume_settings = VolumeConfig(
                name=self.__class__.__name__ + '-' + str(guid))
            self.volume_creator = OpenStackVolume(
                self.os_creds, volume_settings)
            self.volume_creator.create(block=True)

            port_settings = PortConfig(
                name=guid + '-port', network_name=network_settings.name)
            instance_settings = VmInstanceConfig(
                name=guid + '-vm_inst',
                flavor=self.flavor_creator.flavor_settings.name,
                port_settings=[port_settings])
            self.instance_creator = OpenStackVmInstance(
                self.os_creds, instance_settings, image_settings)
            self.instance_creator.create(block=True)
        except:
            self.tearDown()
            raise
コード例 #2
0
ファイル: create_volume_tests.py プロジェクト: opnfv/snaps
    def test_create_two_vol_same_name_diff_proj(self):
        """
        Creates a volume as admin to the project of os_creds then instantiates
        a creator object with the os_creds project to ensure it initializes
        without creation
        """
        vol_name = self.guid + '-vol'
        self.volume_creators.append(
            OpenStackVolume(self.admin_os_creds, VolumeConfig(name=vol_name)))
        admin_vol = self.volume_creators[0].create(block=True)
        self.assertIsNotNone(admin_vol)

        admin_key = keystone_utils.keystone_client(self.admin_os_creds,
                                                   self.admin_os_session)
        admin_proj = keystone_utils.get_project(
            admin_key, project_name=self.admin_os_creds.project_name)
        self.assertEqual(admin_vol.project_id, admin_proj.id)

        admin_cinder = cinder_utils.cinder_client(self.admin_os_creds,
                                                  self.admin_os_session)
        admin_vol_get = cinder_utils.get_volume(
            admin_cinder,
            admin_key,
            volume_name=vol_name,
            project_name=self.admin_os_creds.project_name)
        self.assertIsNotNone(admin_vol_get)
        self.assertEqual(admin_vol, admin_vol_get)

        self.volume_creators.append(
            OpenStackVolume(self.os_creds, VolumeConfig(name=vol_name)))
        proj_vol = self.volume_creators[1].create(block=True)
        self.assertIsNotNone(proj_vol)

        self.assertNotEqual(admin_vol, proj_vol)

        proj_key = keystone_utils.keystone_client(self.os_creds,
                                                  self.os_session)
        proj_cinder = cinder_utils.cinder_client(self.os_creds,
                                                 self.os_session)
        proj_vol_get = cinder_utils.get_volume(
            proj_cinder,
            proj_key,
            volume_name=vol_name,
            project_name=self.os_creds.project_name)

        self.assertIsNotNone(proj_vol_get)
        self.assertEqual(proj_vol, proj_vol_get)
コード例 #3
0
ファイル: volume_tests.py プロジェクト: opnfv/snaps
 def test_config_with_name_only(self):
     settings = VolumeConfig(**{'name': 'foo'})
     self.assertEqual('foo', settings.name)
     self.assertIsNone(settings.project_name)
     self.assertIsNone(settings.description)
     self.assertEquals(1, settings.size)
     self.assertIsNone(settings.image_name)
     self.assertIsNone(settings.type_name)
     self.assertIsNone(settings.availability_zone)
     self.assertFalse(settings.multi_attach)
コード例 #4
0
ファイル: create_volume_tests.py プロジェクト: opnfv/snaps
    def test_bad_volume_type(self):
        """
        Expect a NotFound to be raised when the volume type does not exist
        """
        self.volume_creator = OpenStackVolume(
            self.os_creds, VolumeConfig(name=self.volume_name,
                                        type_name='foo'))

        with self.assertRaises(NotFound):
            self.volume_creator.create()
コード例 #5
0
ファイル: create_volume_tests.py プロジェクト: opnfv/snaps
    def test_bad_image_name(self):
        """
        Tests OpenStackVolume#create() method to ensure a volume is NOT created
        when associating it to an invalid image name
        """
        self.volume_creator = OpenStackVolume(
            self.os_creds, VolumeConfig(name=self.volume_name,
                                        image_name='foo'))

        with self.assertRaises(BadRequest):
            self.volume_creator.create(block=True)
コード例 #6
0
ファイル: settings_utils.py プロジェクト: opnfv/snaps
def create_volume_config(volume):
    """
    Returns a VolumeConfig object
    :param volume: a SNAPS-OO Volume object
    """

    return VolumeConfig(name=volume.name,
                        description=volume.description,
                        size=volume.size,
                        type_name=volume.type,
                        availability_zone=volume.availability_zone,
                        multi_attach=volume.multi_attach)
コード例 #7
0
ファイル: create_volume_tests.py プロジェクト: opnfv/snaps
    def test_valid_volume_type(self):
        """
        Expect a NotFound to be raised when the volume type does not exist
        """
        self.volume_creator = OpenStackVolume(
            self.admin_os_creds,
            VolumeConfig(name=self.volume_name,
                         type_name=self.volume_type_name))

        created_volume = self.volume_creator.create(block=True)
        self.assertIsNotNone(created_volume)
        self.assertEqual(self.volume_type_name, created_volume.type)
コード例 #8
0
ファイル: volume_tests.py プロジェクト: opnfv/snaps
    def test_all_correct_type(self):
        settings = VolumeConfig(
            name='foo', project_name='proj-foo', description='desc', size=2,
            image_name='image', type_name='bar', availability_zone='zone1',
            multi_attach=True)

        self.assertEqual('foo', settings.name)
        self.assertEqual('proj-foo', settings.project_name)
        self.assertEqual('desc', settings.description)
        self.assertEqual(2, settings.size)
        self.assertEqual('image', settings.image_name)
        self.assertEqual('bar', settings.type_name)
        self.assertEqual('zone1', settings.availability_zone)
        self.assertTrue(settings.multi_attach)
コード例 #9
0
ファイル: create_volume_tests.py プロジェクト: opnfv/snaps
    def test_create_volume_bad_image(self):
        """
        Tests the creation of an OpenStack volume with an image that does not
        exist to ensure it raises a BadRequest exception.
        """
        volume_settings = VolumeConfig(name=self.__class__.__name__ + '-' +
                                       str(self.guid),
                                       image_name='foo')

        # Create Volume
        self.volume_creator = OpenStackVolume(self.os_creds, volume_settings)

        with self.assertRaises(BadRequest):
            self.volume_creator.create(block=True)
コード例 #10
0
ファイル: create_volume_tests.py プロジェクト: opnfv/snaps
    def test_create_volume_bad_size(self):
        """
        Tests the creation of an OpenStack volume with a negative size to
        ensure it raises a BadRequest exception.
        """
        volume_settings = VolumeConfig(name=self.__class__.__name__ + '-' +
                                       str(self.guid),
                                       size=-1)

        # Create Volume
        self.volume_creator = OpenStackVolume(self.os_creds, volume_settings)

        with self.assertRaises(BadRequest):
            self.volume_creator.create(block=True)
コード例 #11
0
ファイル: volume_tests.py プロジェクト: opnfv/snaps
    def test_config_all(self):
        settings = VolumeConfig(
            **{'name': 'foo', 'project_name': 'proj-foo',
               'description': 'desc', 'size': '2',
               'image_name': 'foo', 'type_name': 'bar',
               'availability_zone': 'zone1', 'multi_attach': 'true'})

        self.assertEqual('foo', settings.name)
        self.assertEqual('proj-foo', settings.project_name)
        self.assertEqual('desc', settings.description)
        self.assertEqual(2, settings.size)
        self.assertEqual('foo', settings.image_name)
        self.assertEqual('bar', settings.type_name)
        self.assertEqual('zone1', settings.availability_zone)
        self.assertTrue(settings.multi_attach)
コード例 #12
0
ファイル: create_volume_tests.py プロジェクト: opnfv/snaps
    def setUp(self):
        """
        Instantiates the CreateVolume object that is responsible for
        downloading and creating an OS volume file within OpenStack
        """
        super(self.__class__, self).__start__()

        guid = uuid.uuid4()
        self.volume_settings = VolumeConfig(name=self.__class__.__name__ +
                                            '-' + str(guid))

        self.cinder = cinder_utils.cinder_client(self.os_creds,
                                                 self.os_session)
        self.keystone = keystone_utils.keystone_client(self.os_creds,
                                                       self.os_session)
        self.volume_creator = None
コード例 #13
0
ファイル: cinder_utils_tests.py プロジェクト: opnfv/snaps
    def test_create_simple_volume(self):
        """
        Tests the cinder_utils.create_volume()
        """
        volume_settings = VolumeConfig(name=self.volume_name)
        self.volume = cinder_utils.create_volume(
            self.cinder, self.keystone, volume_settings)
        self.assertIsNotNone(self.volume)
        self.assertEqual(self.volume_name, self.volume.name)

        self.assertTrue(volume_active(self.cinder, self.volume))

        volume = cinder_utils.get_volume(
            self.cinder, self.keystone, volume_settings=volume_settings,
            project_name=self.os_creds.project_name)
        self.assertIsNotNone(volume)
        validation_utils.objects_equivalent(self.volume, volume)
コード例 #14
0
ファイル: create_volume_tests.py プロジェクト: opnfv/snaps
    def test_valid_volume_image(self):
        """
        Tests OpenStackVolume#create() method to ensure a volume is NOT created
        when associating it to an invalid image name
        """
        self.volume_creator = OpenStackVolume(
            self.os_creds,
            VolumeConfig(name=self.volume_name, image_name=self.image_name))

        created_volume = self.volume_creator.create(block=True)
        self.assertIsNotNone(created_volume)
        self.assertEqual(self.volume_creator.volume_settings.name,
                         created_volume.name)
        self.assertTrue(self.volume_creator.volume_active())

        retrieved_volume = cinder_utils.get_volume_by_id(
            self.cinder, created_volume.id)

        self.assertEqual(created_volume, retrieved_volume)
コード例 #15
0
ファイル: volume_tests.py プロジェクト: opnfv/snaps
 def test_empty_config(self):
     with self.assertRaises(VolumeConfigError):
         VolumeConfig(**dict())
コード例 #16
0
ファイル: volume_tests.py プロジェクト: opnfv/snaps
 def test_no_params(self):
     with self.assertRaises(VolumeConfigError):
         VolumeConfig()