Exemple #1
0
    def test_list_flavors(self):
        mock_uri = '{endpoint}/flavors/detail?is_public=None'.format(
            endpoint=fakes.COMPUTE_ENDPOINT)

        uris_to_mock = [
            dict(method='GET',
                 uri=mock_uri,
                 validate=dict(
                     headers={'OpenStack-API-Version': 'compute 2.53'}),
                 json={'flavors': []}),
            dict(method='GET',
                 uri=mock_uri,
                 validate=dict(
                     headers={'OpenStack-API-Version': 'compute 2.53'}),
                 json={'flavors': fakes.FAKE_FLAVOR_LIST})
        ]
        self.use_compute_discovery()

        self.register_uris(uris_to_mock)

        self.assertEqual([], self.cloud.list_flavors())

        self.assertEqual([], self.cloud.list_flavors())

        fake_flavor_dicts = [
            _flavor.Flavor(connection=self.cloud, **f)
            for f in fakes.FAKE_FLAVOR_LIST
        ]

        self.cloud.list_flavors.invalidate(self.cloud)
        self.assertEqual(fake_flavor_dicts, self.cloud.list_flavors())

        self.assert_calls()
 def test_make_it(self):
     sot = flavor.Flavor(EXAMPLE)
     self.assertEqual(EXAMPLE['disk'], sot.disk)
     self.assertEqual(EXAMPLE['id'], sot.id)
     self.assertEqual(EXAMPLE['os-flavor-access:is_public'], sot.is_public)
     self.assertEqual(EXAMPLE['links'], sot.links)
     self.assertEqual(EXAMPLE['name'], sot.name)
     self.assertEqual(EXAMPLE['ram'], sot.ram)
     self.assertEqual(EXAMPLE['vcpus'], sot.vcpus)
 def test_basic(self):
     sot = flavor.Flavor()
     self.assertEqual('flavor', sot.resource_key)
     self.assertEqual('flavors', sot.resources_key)
     self.assertEqual('/flavors', sot.base_path)
     self.assertEqual('compute', sot.service.service_type)
     self.assertTrue(sot.allow_create)
     self.assertTrue(sot.allow_retrieve)
     self.assertTrue(sot.allow_update)
     self.assertTrue(sot.allow_delete)
     self.assertTrue(sot.allow_list)
Exemple #4
0
 def test_flavor_get_no_extra(self):
     """fetch extra_specs not triggered"""
     with mock.patch('openstack.compute.v2.flavor.Flavor.fetch_extra_specs'
                     ) as mocked:
         res = flavor.Flavor()
         mocked.return_value = res
         self._verify('openstack.proxy.Proxy._get',
                      self.proxy.get_flavor,
                      method_args=['res'],
                      expected_result=res,
                      expected_args=[flavor.Flavor, 'res'])
         mocked.assert_not_called()
Exemple #5
0
 def test_flavor_find_skip_fetch_extra(self):
     """fetch extra_specs not triggered"""
     with mock.patch('openstack.compute.v2.flavor.Flavor.fetch_extra_specs'
                     ) as mocked:
         res = flavor.Flavor(extra_specs={'a': 'b'})
         mocked.return_value = res
         self._verify('openstack.proxy.Proxy._find',
                      self.proxy.find_flavor,
                      method_args=['res', True],
                      expected_result=res,
                      expected_args=[flavor.Flavor, 'res'],
                      expected_kwargs={'ignore_missing': True})
         mocked.assert_not_called()
Exemple #6
0
    def test_delete_extra_specs_property(self):
        sot = flavor.Flavor(**BASIC_EXAMPLE)
        resp = mock.Mock()
        resp.body = None
        resp.json = mock.Mock(return_value=resp.body)
        resp.status_code = 200
        self.sess.delete = mock.Mock(return_value=resp)

        rsp = sot.delete_extra_specs_property(self.sess, 'a')

        self.sess.delete.assert_called_with(
            'flavors/IDENTIFIER/os-extra_specs/a',
            microversion=self.sess.default_microversion)

        self.assertIsNone(rsp)
Exemple #7
0
    def test_get_extra_specs_property(self):
        sot = flavor.Flavor(**BASIC_EXAMPLE)
        resp = mock.Mock()
        resp.body = {'a': 'b'}
        resp.json = mock.Mock(return_value=resp.body)
        resp.status_code = 200
        self.sess.get = mock.Mock(return_value=resp)

        rsp = sot.get_extra_specs_property(self.sess, 'a')

        self.sess.get.assert_called_with(
            'flavors/IDENTIFIER/os-extra_specs/a',
            microversion=self.sess.default_microversion)

        self.assertEqual('b', rsp)
Exemple #8
0
 def test_make_basic(self):
     sot = flavor.Flavor(**BASIC_EXAMPLE)
     self.assertEqual(BASIC_EXAMPLE['id'], sot.id)
     self.assertEqual(BASIC_EXAMPLE['links'], sot.links)
     self.assertEqual(BASIC_EXAMPLE['name'], sot.name)
     self.assertEqual(BASIC_EXAMPLE['disk'], sot.disk)
     self.assertEqual(BASIC_EXAMPLE['os-flavor-access:is_public'],
                      sot.is_public)
     self.assertEqual(BASIC_EXAMPLE['ram'], sot.ram)
     self.assertEqual(BASIC_EXAMPLE['vcpus'], sot.vcpus)
     self.assertEqual(BASIC_EXAMPLE['swap'], sot.swap)
     self.assertEqual(BASIC_EXAMPLE['OS-FLV-EXT-DATA:ephemeral'],
                      sot.ephemeral)
     self.assertEqual(BASIC_EXAMPLE['OS-FLV-DISABLED:disabled'],
                      sot.is_disabled)
     self.assertEqual(BASIC_EXAMPLE['rxtx_factor'], sot.rxtx_factor)
Exemple #9
0
    def test_add_tenant_access(self):
        sot = flavor.Flavor(**BASIC_EXAMPLE)
        resp = mock.Mock()
        resp.body = None
        resp.json = mock.Mock(return_value=resp.body)
        resp.status_code = 200
        self.sess.post = mock.Mock(return_value=resp)

        sot.add_tenant_access(self.sess, 'fake_tenant')

        self.sess.post.assert_called_with(
            'flavors/IDENTIFIER/action',
            json={'addTenantAccess': {
                'tenant': 'fake_tenant'
            }},
            headers={'Accept': ''})
Exemple #10
0
    def test_fetch_extra_specs(self):
        sot = flavor.Flavor(**BASIC_EXAMPLE)
        resp = mock.Mock()
        resp.body = {'extra_specs': {'a': 'b', 'c': 'd'}}
        resp.json = mock.Mock(return_value=resp.body)
        resp.status_code = 200
        self.sess.get = mock.Mock(return_value=resp)

        rsp = sot.fetch_extra_specs(self.sess)

        self.sess.get.assert_called_with(
            'flavors/IDENTIFIER/os-extra_specs',
            microversion=self.sess.default_microversion)

        self.assertEqual(resp.body['extra_specs'], rsp.extra_specs)
        self.assertIsInstance(rsp, flavor.Flavor)
Exemple #11
0
    def test_get_flavor_access(self):
        sot = flavor.Flavor(**BASIC_EXAMPLE)
        resp = mock.Mock()
        resp.body = {'flavor_access': [
            {'flavor_id': 'fake_flavor',
             'tenant_id': 'fake_tenant'}
        ]}
        resp.json = mock.Mock(return_value=resp.body)
        resp.status_code = 200
        self.sess.get = mock.Mock(return_value=resp)

        rsp = sot.get_access(self.sess)

        self.sess.get.assert_called_with(
            'flavors/IDENTIFIER/os-flavor-access',
        )

        self.assertEqual(resp.body['flavor_access'], rsp)
Exemple #12
0
    def test_basic(self):
        sot = flavor.Flavor()
        self.assertEqual('flavor', sot.resource_key)
        self.assertEqual('flavors', sot.resources_key)
        self.assertEqual('/flavors', sot.base_path)
        self.assertTrue(sot.allow_create)
        self.assertTrue(sot.allow_fetch)
        self.assertTrue(sot.allow_delete)
        self.assertTrue(sot.allow_list)
        self.assertTrue(sot.allow_commit)

        self.assertDictEqual({"sort_key": "sort_key",
                              "sort_dir": "sort_dir",
                              "min_disk": "minDisk",
                              "min_ram": "minRam",
                              "limit": "limit",
                              "marker": "marker",
                              "is_public": "is_public"},
                             sot._query_mapping._mapping)
    def test_basic(self):
        sot = flavor.Flavor()
        self.assertEqual('flavor', sot.resource_key)
        self.assertEqual('flavors', sot.resources_key)
        self.assertEqual('/flavors', sot.base_path)
        self.assertEqual('compute', sot.service.service_type)
        self.assertTrue(sot.allow_create)
        self.assertTrue(sot.allow_get)
        self.assertTrue(sot.allow_delete)
        self.assertTrue(sot.allow_list)
        self.assertFalse(sot.allow_update)

        self.assertDictEqual(
            {
                "sort_key": "sort_key",
                "sort_dir": "sort_dir",
                "min_disk": "minDisk",
                "min_ram": "minRam"
            }, sot._query_mapping._mapping)
Exemple #14
0
 def update_flavor(self, **data):
     return flavor.Flavor(data).update(self.session)
Exemple #15
0
 def get_flavor(self, **data):
     return flavor.Flavor(data).get(self.session)
Exemple #16
0
    def test_flavor_create_other_options(self):

        self.flavor.is_public = False
        arglist = [
            '--id',
            'auto',
            '--ram',
            str(self.flavor.ram),
            '--disk',
            str(self.flavor.disk),
            '--ephemeral',
            str(self.flavor.ephemeral),
            '--swap',
            str(self.flavor.swap),
            '--vcpus',
            str(self.flavor.vcpus),
            '--rxtx-factor',
            str(self.flavor.rxtx_factor),
            '--private',
            '--description',
            str(self.flavor.description),
            '--project',
            self.project.id,
            '--property',
            'key1=value1',
            '--property',
            'key2=value2',
            self.flavor.name,
        ]
        verifylist = [
            ('ram', self.flavor.ram),
            ('disk', self.flavor.disk),
            ('ephemeral', self.flavor.ephemeral),
            ('swap', self.flavor.swap),
            ('vcpus', self.flavor.vcpus),
            ('rxtx_factor', self.flavor.rxtx_factor),
            ('public', False),
            ('description', 'description'),
            ('project', self.project.id),
            ('properties', {
                'key1': 'value1',
                'key2': 'value2'
            }),
            ('name', self.flavor.name),
        ]
        parsed_args = self.check_parser(self.cmd, arglist, verifylist)

        args = {
            'name': self.flavor.name,
            'ram': self.flavor.ram,
            'vcpus': self.flavor.vcpus,
            'disk': self.flavor.disk,
            'id': 'auto',
            'ephemeral': self.flavor.ephemeral,
            'swap': self.flavor.swap,
            'rxtx_factor': self.flavor.rxtx_factor,
            'is_public': False,
            'description': self.flavor.description
        }

        props = {'key1': 'value1', 'key2': 'value2'}

        # SDK updates the flavor object instance. In order to make the
        # verification clear and preciese let's create new flavor and change
        # expected props this way
        create_flavor = _flavor.Flavor(**self.flavor)
        expected_flavor = _flavor.Flavor(**self.flavor)
        expected_flavor.extra_specs = props
        expected_flavor.is_public = False
        # convert expected data tuple to list to be able to modify it
        cmp_data = list(self.data_private)
        cmp_data[7] = format_columns.DictColumn(props)
        self.sdk_client.create_flavor.return_value = create_flavor
        self.sdk_client.create_flavor_extra_specs.return_value = \
            expected_flavor

        with mock.patch.object(sdk_utils,
                               'supports_microversion',
                               return_value=True):
            columns, data = self.cmd.take_action(parsed_args)
        self.sdk_client.create_flavor.assert_called_once_with(**args)
        self.sdk_client.flavor_add_tenant_access.assert_called_with(
            self.flavor.id,
            self.project.id,
        )
        self.sdk_client.create_flavor_extra_specs.assert_called_with(
            create_flavor, props)
        self.assertEqual(self.columns, columns)
        self.assertCountEqual(cmp_data, data)