2015-01-30 13:04:45 -08:00
|
|
|
# Copyright 2015 Symantec Corporation
|
|
|
|
#
|
|
|
|
# Licensed under the Apache License, Version 2.0 (the "License"); you may
|
|
|
|
# not use this file except in compliance with the License. You may obtain
|
|
|
|
# a copy of the License at
|
|
|
|
#
|
|
|
|
# http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
#
|
|
|
|
# Unless required by applicable law or agreed to in writing, software
|
|
|
|
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
|
|
|
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
|
|
|
# License for the specific language governing permissions and limitations
|
|
|
|
# under the License.
|
|
|
|
#
|
|
|
|
|
2020-01-10 14:21:47 -06:00
|
|
|
from unittest import mock
|
|
|
|
from unittest.mock import call
|
2016-05-26 20:00:12 +08:00
|
|
|
|
2018-06-14 18:20:04 +08:00
|
|
|
import novaclient
|
2020-11-02 13:25:59 +01:00
|
|
|
from osc_lib.cli import format_columns
|
2016-06-08 14:17:14 -05:00
|
|
|
from osc_lib import exceptions
|
|
|
|
|
2015-01-30 13:04:45 -08:00
|
|
|
from openstackclient.compute.v2 import flavor
|
2016-09-05 22:14:33 -07:00
|
|
|
from openstackclient.tests.unit.compute.v2 import fakes as compute_fakes
|
|
|
|
from openstackclient.tests.unit.identity.v3 import fakes as identity_fakes
|
|
|
|
from openstackclient.tests.unit import utils as tests_utils
|
2015-01-30 13:04:45 -08:00
|
|
|
|
|
|
|
|
|
|
|
class TestFlavor(compute_fakes.TestComputev2):
|
|
|
|
|
|
|
|
def setUp(self):
|
|
|
|
super(TestFlavor, self).setUp()
|
|
|
|
|
|
|
|
# Get a shortcut to the FlavorManager Mock
|
|
|
|
self.flavors_mock = self.app.client_manager.compute.flavors
|
|
|
|
self.flavors_mock.reset_mock()
|
|
|
|
|
2016-05-26 20:00:12 +08:00
|
|
|
# Get a shortcut to the FlavorAccessManager Mock
|
|
|
|
self.flavor_access_mock = self.app.client_manager.compute.flavor_access
|
|
|
|
self.flavor_access_mock.reset_mock()
|
|
|
|
|
|
|
|
self.projects_mock = self.app.client_manager.identity.projects
|
|
|
|
self.projects_mock.reset_mock()
|
|
|
|
|
2015-01-30 13:04:45 -08:00
|
|
|
|
2016-05-04 18:55:49 +08:00
|
|
|
class TestFlavorCreate(TestFlavor):
|
|
|
|
|
|
|
|
flavor = compute_fakes.FakeFlavor.create_one_flavor(
|
|
|
|
attrs={'links': 'flavor-links'})
|
2016-07-15 19:02:18 +08:00
|
|
|
project = identity_fakes.FakeProject.create_one_project()
|
2016-05-04 18:55:49 +08:00
|
|
|
columns = (
|
|
|
|
'OS-FLV-DISABLED:disabled',
|
|
|
|
'OS-FLV-EXT-DATA:ephemeral',
|
2018-06-14 18:20:04 +08:00
|
|
|
'description',
|
2016-05-04 18:55:49 +08:00
|
|
|
'disk',
|
|
|
|
'id',
|
|
|
|
'name',
|
|
|
|
'os-flavor-access:is_public',
|
2016-06-28 14:39:00 +08:00
|
|
|
'properties',
|
2016-05-04 18:55:49 +08:00
|
|
|
'ram',
|
|
|
|
'rxtx_factor',
|
|
|
|
'swap',
|
|
|
|
'vcpus',
|
|
|
|
)
|
|
|
|
data = (
|
|
|
|
flavor.disabled,
|
|
|
|
flavor.ephemeral,
|
2018-06-14 18:20:04 +08:00
|
|
|
flavor.description,
|
2016-05-04 18:55:49 +08:00
|
|
|
flavor.disk,
|
|
|
|
flavor.id,
|
|
|
|
flavor.name,
|
|
|
|
flavor.is_public,
|
2020-11-02 13:25:59 +01:00
|
|
|
format_columns.DictColumn(flavor.properties),
|
2016-05-04 18:55:49 +08:00
|
|
|
flavor.ram,
|
|
|
|
flavor.rxtx_factor,
|
|
|
|
flavor.swap,
|
|
|
|
flavor.vcpus,
|
|
|
|
)
|
|
|
|
|
|
|
|
def setUp(self):
|
|
|
|
super(TestFlavorCreate, self).setUp()
|
|
|
|
|
2016-06-15 13:34:15 +08:00
|
|
|
# Return a project
|
2016-07-15 19:02:18 +08:00
|
|
|
self.projects_mock.get.return_value = self.project
|
2016-05-04 18:55:49 +08:00
|
|
|
self.flavors_mock.create.return_value = self.flavor
|
|
|
|
self.cmd = flavor.CreateFlavor(self.app, None)
|
|
|
|
|
|
|
|
def test_flavor_create_default_options(self):
|
|
|
|
|
|
|
|
arglist = [
|
|
|
|
self.flavor.name
|
|
|
|
]
|
|
|
|
verifylist = [
|
|
|
|
('name', self.flavor.name),
|
|
|
|
]
|
|
|
|
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
|
|
|
|
|
|
|
|
default_args = (
|
|
|
|
self.flavor.name,
|
|
|
|
256,
|
|
|
|
1,
|
|
|
|
0,
|
|
|
|
'auto',
|
|
|
|
0,
|
|
|
|
0,
|
|
|
|
1.0,
|
2018-06-14 18:20:04 +08:00
|
|
|
True,
|
|
|
|
None,
|
2016-05-04 18:55:49 +08:00
|
|
|
)
|
|
|
|
columns, data = self.cmd.take_action(parsed_args)
|
|
|
|
self.flavors_mock.create.assert_called_once_with(*default_args)
|
|
|
|
|
|
|
|
self.assertEqual(self.columns, columns)
|
2020-11-02 13:25:59 +01:00
|
|
|
self.assertItemEqual(self.data, data)
|
2016-05-04 18:55:49 +08:00
|
|
|
|
|
|
|
def test_flavor_create_all_options(self):
|
|
|
|
|
|
|
|
arglist = [
|
|
|
|
'--id', self.flavor.id,
|
|
|
|
'--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),
|
|
|
|
'--public',
|
2018-06-14 18:20:04 +08:00
|
|
|
'--description', str(self.flavor.description),
|
2016-06-28 14:39:00 +08:00
|
|
|
'--property', 'property=value',
|
|
|
|
self.flavor.name,
|
2016-05-04 18:55:49 +08:00
|
|
|
]
|
|
|
|
verifylist = [
|
|
|
|
('id', self.flavor.id),
|
|
|
|
('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', True),
|
2018-06-14 18:20:04 +08:00
|
|
|
('description', self.flavor.description),
|
2016-06-28 14:39:00 +08:00
|
|
|
('property', {'property': 'value'}),
|
|
|
|
('name', self.flavor.name),
|
2016-05-04 18:55:49 +08:00
|
|
|
]
|
|
|
|
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
|
|
|
|
|
|
|
|
args = (
|
|
|
|
self.flavor.name,
|
|
|
|
self.flavor.ram,
|
|
|
|
self.flavor.vcpus,
|
|
|
|
self.flavor.disk,
|
|
|
|
self.flavor.id,
|
|
|
|
self.flavor.ephemeral,
|
|
|
|
self.flavor.swap,
|
|
|
|
self.flavor.rxtx_factor,
|
|
|
|
self.flavor.is_public,
|
2018-06-14 18:20:04 +08:00
|
|
|
self.flavor.description,
|
2016-05-04 18:55:49 +08:00
|
|
|
)
|
2018-06-14 18:20:04 +08:00
|
|
|
self.app.client_manager.compute.api_version = 2.55
|
|
|
|
with mock.patch.object(novaclient.api_versions,
|
|
|
|
'APIVersion',
|
|
|
|
return_value=2.55):
|
|
|
|
columns, data = self.cmd.take_action(parsed_args)
|
2016-05-04 18:55:49 +08:00
|
|
|
self.flavors_mock.create.assert_called_once_with(*args)
|
2016-06-28 14:39:00 +08:00
|
|
|
self.flavor.set_keys.assert_called_once_with({'property': 'value'})
|
|
|
|
self.flavor.get_keys.assert_called_once_with()
|
2016-05-04 18:55:49 +08:00
|
|
|
|
|
|
|
self.assertEqual(self.columns, columns)
|
2020-11-02 13:25:59 +01:00
|
|
|
self.assertItemEqual(self.data, data)
|
2016-05-04 18:55:49 +08:00
|
|
|
|
|
|
|
def test_flavor_create_other_options(self):
|
|
|
|
|
|
|
|
self.flavor.is_public = False
|
|
|
|
arglist = [
|
2017-01-05 12:34:43 +01:00
|
|
|
'--id', 'auto',
|
2016-05-04 18:55:49 +08:00
|
|
|
'--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',
|
2018-06-14 18:20:04 +08:00
|
|
|
'--description', str(self.flavor.description),
|
2016-07-15 19:02:18 +08:00
|
|
|
'--project', self.project.id,
|
2016-06-28 14:39:00 +08:00
|
|
|
'--property', 'key1=value1',
|
|
|
|
'--property', 'key2=value2',
|
|
|
|
self.flavor.name,
|
2016-05-04 18:55:49 +08:00
|
|
|
]
|
|
|
|
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),
|
2018-06-14 18:20:04 +08:00
|
|
|
('description', 'description'),
|
2016-07-15 19:02:18 +08:00
|
|
|
('project', self.project.id),
|
2016-06-28 14:39:00 +08:00
|
|
|
('property', {'key1': 'value1', 'key2': 'value2'}),
|
|
|
|
('name', self.flavor.name),
|
2016-05-04 18:55:49 +08:00
|
|
|
]
|
|
|
|
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
|
|
|
|
|
|
|
|
args = (
|
|
|
|
self.flavor.name,
|
|
|
|
self.flavor.ram,
|
|
|
|
self.flavor.vcpus,
|
|
|
|
self.flavor.disk,
|
2017-01-05 12:34:43 +01:00
|
|
|
'auto',
|
2016-05-04 18:55:49 +08:00
|
|
|
self.flavor.ephemeral,
|
|
|
|
self.flavor.swap,
|
|
|
|
self.flavor.rxtx_factor,
|
|
|
|
self.flavor.is_public,
|
2018-06-14 18:20:04 +08:00
|
|
|
self.flavor.description,
|
2016-05-04 18:55:49 +08:00
|
|
|
)
|
2018-06-14 18:20:04 +08:00
|
|
|
self.app.client_manager.compute.api_version = 2.55
|
|
|
|
with mock.patch.object(novaclient.api_versions,
|
|
|
|
'APIVersion',
|
|
|
|
return_value=2.55):
|
|
|
|
columns, data = self.cmd.take_action(parsed_args)
|
2016-05-04 18:55:49 +08:00
|
|
|
self.flavors_mock.create.assert_called_once_with(*args)
|
2016-06-15 13:34:15 +08:00
|
|
|
self.flavor_access_mock.add_tenant_access.assert_called_with(
|
|
|
|
self.flavor.id,
|
2016-07-15 19:02:18 +08:00
|
|
|
self.project.id,
|
2016-06-15 13:34:15 +08:00
|
|
|
)
|
2016-06-28 14:39:00 +08:00
|
|
|
self.flavor.set_keys.assert_called_with(
|
|
|
|
{'key1': 'value1', 'key2': 'value2'})
|
|
|
|
self.flavor.get_keys.assert_called_with()
|
2016-05-04 18:55:49 +08:00
|
|
|
self.assertEqual(self.columns, columns)
|
2020-11-02 13:25:59 +01:00
|
|
|
self.assertItemEqual(self.data, data)
|
2016-05-04 18:55:49 +08:00
|
|
|
|
2016-06-15 13:34:15 +08:00
|
|
|
def test_public_flavor_create_with_project(self):
|
|
|
|
arglist = [
|
2016-07-15 19:02:18 +08:00
|
|
|
'--project', self.project.id,
|
2016-06-15 13:34:15 +08:00
|
|
|
self.flavor.name,
|
|
|
|
]
|
|
|
|
verifylist = [
|
2016-07-15 19:02:18 +08:00
|
|
|
('project', self.project.id),
|
2016-06-15 13:34:15 +08:00
|
|
|
('name', self.flavor.name),
|
|
|
|
]
|
|
|
|
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
|
|
|
|
|
|
|
|
self.assertRaises(exceptions.CommandError,
|
|
|
|
self.cmd.take_action,
|
|
|
|
parsed_args)
|
|
|
|
|
2016-05-04 18:55:49 +08:00
|
|
|
def test_flavor_create_no_options(self):
|
|
|
|
arglist = []
|
|
|
|
verifylist = None
|
|
|
|
self.assertRaises(tests_utils.ParserException,
|
|
|
|
self.check_parser,
|
|
|
|
self.cmd,
|
|
|
|
arglist,
|
|
|
|
verifylist)
|
|
|
|
|
2018-06-14 18:20:04 +08:00
|
|
|
def test_flavor_create_with_description_api_newer(self):
|
|
|
|
arglist = [
|
|
|
|
'--id', self.flavor.id,
|
|
|
|
'--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', 'fake description',
|
|
|
|
self.flavor.name,
|
|
|
|
]
|
|
|
|
verifylist = [
|
|
|
|
('id', self.flavor.id),
|
|
|
|
('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', 'fake description'),
|
|
|
|
('name', self.flavor.name),
|
|
|
|
]
|
|
|
|
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
|
|
|
|
self.app.client_manager.compute.api_version = 2.55
|
|
|
|
with mock.patch.object(novaclient.api_versions,
|
|
|
|
'APIVersion',
|
|
|
|
return_value=2.55):
|
|
|
|
columns, data = self.cmd.take_action(parsed_args)
|
|
|
|
|
|
|
|
args = (
|
|
|
|
self.flavor.name,
|
|
|
|
self.flavor.ram,
|
|
|
|
self.flavor.vcpus,
|
|
|
|
self.flavor.disk,
|
|
|
|
self.flavor.id,
|
|
|
|
self.flavor.ephemeral,
|
|
|
|
self.flavor.swap,
|
|
|
|
self.flavor.rxtx_factor,
|
|
|
|
False,
|
|
|
|
'fake description',
|
|
|
|
)
|
|
|
|
|
|
|
|
self.flavors_mock.create.assert_called_once_with(*args)
|
|
|
|
|
|
|
|
self.assertEqual(self.columns, columns)
|
2020-11-02 13:25:59 +01:00
|
|
|
self.assertItemEqual(self.data, data)
|
2018-06-14 18:20:04 +08:00
|
|
|
|
|
|
|
def test_flavor_create_with_description_api_older(self):
|
|
|
|
arglist = [
|
|
|
|
'--id', self.flavor.id,
|
|
|
|
'--ram', str(self.flavor.ram),
|
|
|
|
'--vcpus', str(self.flavor.vcpus),
|
|
|
|
'--description', 'description',
|
|
|
|
self.flavor.name,
|
|
|
|
]
|
|
|
|
verifylist = [
|
|
|
|
('ram', self.flavor.ram),
|
|
|
|
('vcpus', self.flavor.vcpus),
|
|
|
|
('description', 'description'),
|
|
|
|
('name', self.flavor.name),
|
|
|
|
]
|
|
|
|
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
|
|
|
|
|
|
|
|
self.app.client_manager.compute.api_version = 2.54
|
|
|
|
with mock.patch.object(novaclient.api_versions,
|
|
|
|
'APIVersion',
|
|
|
|
return_value=2.55):
|
|
|
|
self.assertRaises(exceptions.CommandError, self.cmd.take_action,
|
|
|
|
parsed_args)
|
|
|
|
|
2016-05-04 18:55:49 +08:00
|
|
|
|
2015-11-30 00:18:17 -05:00
|
|
|
class TestFlavorDelete(TestFlavor):
|
|
|
|
|
2016-06-20 15:42:40 +08:00
|
|
|
flavors = compute_fakes.FakeFlavor.create_flavors(count=2)
|
2015-11-30 00:18:17 -05:00
|
|
|
|
|
|
|
def setUp(self):
|
|
|
|
super(TestFlavorDelete, self).setUp()
|
|
|
|
|
2016-06-20 15:42:40 +08:00
|
|
|
self.flavors_mock.get = (
|
|
|
|
compute_fakes.FakeFlavor.get_flavors(self.flavors))
|
2015-11-30 00:18:17 -05:00
|
|
|
self.flavors_mock.delete.return_value = None
|
|
|
|
|
|
|
|
self.cmd = flavor.DeleteFlavor(self.app, None)
|
|
|
|
|
|
|
|
def test_flavor_delete(self):
|
|
|
|
arglist = [
|
2016-06-20 15:42:40 +08:00
|
|
|
self.flavors[0].id
|
2015-11-30 00:18:17 -05:00
|
|
|
]
|
|
|
|
verifylist = [
|
2016-06-20 15:42:40 +08:00
|
|
|
('flavor', [self.flavors[0].id]),
|
2015-11-30 00:18:17 -05:00
|
|
|
]
|
|
|
|
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
|
|
|
|
|
2016-02-27 15:38:04 +08:00
|
|
|
result = self.cmd.take_action(parsed_args)
|
2015-11-30 00:18:17 -05:00
|
|
|
|
2016-06-20 15:42:40 +08:00
|
|
|
self.flavors_mock.delete.assert_called_with(self.flavors[0].id)
|
2016-02-27 15:38:04 +08:00
|
|
|
self.assertIsNone(result)
|
2015-11-30 00:18:17 -05:00
|
|
|
|
2016-06-20 15:42:40 +08:00
|
|
|
def test_delete_multiple_flavors(self):
|
|
|
|
arglist = []
|
|
|
|
for f in self.flavors:
|
|
|
|
arglist.append(f.id)
|
|
|
|
verifylist = [
|
|
|
|
('flavor', arglist),
|
|
|
|
]
|
|
|
|
|
|
|
|
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
|
|
|
|
result = self.cmd.take_action(parsed_args)
|
2015-11-30 00:18:17 -05:00
|
|
|
|
2016-06-20 15:42:40 +08:00
|
|
|
calls = []
|
|
|
|
for f in self.flavors:
|
|
|
|
calls.append(call(f.id))
|
|
|
|
self.flavors_mock.delete.assert_has_calls(calls)
|
|
|
|
self.assertIsNone(result)
|
|
|
|
|
|
|
|
def test_multi_flavors_delete_with_exception(self):
|
2015-11-30 00:18:17 -05:00
|
|
|
arglist = [
|
2016-06-20 15:42:40 +08:00
|
|
|
self.flavors[0].id,
|
|
|
|
'unexist_flavor',
|
2015-11-30 00:18:17 -05:00
|
|
|
]
|
|
|
|
verifylist = [
|
2016-06-20 15:42:40 +08:00
|
|
|
('flavor', [self.flavors[0].id, 'unexist_flavor'])
|
2015-11-30 00:18:17 -05:00
|
|
|
]
|
|
|
|
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
|
|
|
|
|
2016-06-20 15:42:40 +08:00
|
|
|
find_mock_result = [self.flavors[0], exceptions.CommandError]
|
|
|
|
self.flavors_mock.get = (
|
2016-09-14 13:27:31 +08:00
|
|
|
mock.Mock(side_effect=find_mock_result)
|
2016-06-20 15:42:40 +08:00
|
|
|
)
|
|
|
|
self.flavors_mock.find.side_effect = exceptions.NotFound(None)
|
|
|
|
|
|
|
|
try:
|
|
|
|
self.cmd.take_action(parsed_args)
|
|
|
|
self.fail('CommandError should be raised.')
|
|
|
|
except exceptions.CommandError as e:
|
|
|
|
self.assertEqual('1 of 2 flavors failed to delete.', str(e))
|
|
|
|
|
|
|
|
self.flavors_mock.get.assert_any_call(self.flavors[0].id)
|
|
|
|
self.flavors_mock.get.assert_any_call('unexist_flavor')
|
|
|
|
self.flavors_mock.delete.assert_called_once_with(self.flavors[0].id)
|
2015-11-30 00:18:17 -05:00
|
|
|
|
|
|
|
|
2015-01-30 13:04:45 -08:00
|
|
|
class TestFlavorList(TestFlavor):
|
|
|
|
|
2015-11-28 15:17:50 +08:00
|
|
|
# Return value of self.flavors_mock.list().
|
|
|
|
flavors = compute_fakes.FakeFlavor.create_flavors(count=1)
|
|
|
|
|
2015-11-28 14:05:20 +08:00
|
|
|
columns = (
|
|
|
|
'ID',
|
|
|
|
'Name',
|
|
|
|
'RAM',
|
|
|
|
'Disk',
|
|
|
|
'Ephemeral',
|
|
|
|
'VCPUs',
|
|
|
|
'Is Public',
|
|
|
|
)
|
|
|
|
columns_long = columns + (
|
|
|
|
'Swap',
|
|
|
|
'RXTX Factor',
|
|
|
|
'Properties'
|
|
|
|
)
|
|
|
|
|
2015-11-28 14:26:09 +08:00
|
|
|
data = ((
|
2015-11-28 15:17:50 +08:00
|
|
|
flavors[0].id,
|
|
|
|
flavors[0].name,
|
|
|
|
flavors[0].ram,
|
2016-02-20 10:34:40 +08:00
|
|
|
flavors[0].disk,
|
|
|
|
flavors[0].ephemeral,
|
2015-11-28 15:17:50 +08:00
|
|
|
flavors[0].vcpus,
|
2016-02-20 10:34:40 +08:00
|
|
|
flavors[0].is_public,
|
2015-11-28 14:26:09 +08:00
|
|
|
), )
|
|
|
|
data_long = (data[0] + (
|
2016-02-20 10:34:40 +08:00
|
|
|
flavors[0].swap,
|
|
|
|
flavors[0].rxtx_factor,
|
2020-11-02 13:25:59 +01:00
|
|
|
format_columns.DictColumn(flavors[0].properties)
|
2015-11-28 14:26:09 +08:00
|
|
|
), )
|
|
|
|
|
2015-01-30 13:04:45 -08:00
|
|
|
def setUp(self):
|
|
|
|
super(TestFlavorList, self).setUp()
|
|
|
|
|
2015-11-28 15:17:50 +08:00
|
|
|
self.flavors_mock.list.return_value = self.flavors
|
2015-01-30 13:04:45 -08:00
|
|
|
|
|
|
|
# Get the command object to test
|
|
|
|
self.cmd = flavor.ListFlavor(self.app, None)
|
|
|
|
|
|
|
|
def test_flavor_list_no_options(self):
|
|
|
|
arglist = []
|
|
|
|
verifylist = [
|
|
|
|
('public', True),
|
|
|
|
('all', False),
|
|
|
|
('long', False),
|
|
|
|
]
|
|
|
|
|
|
|
|
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
|
|
|
|
|
2016-02-10 19:01:52 +08:00
|
|
|
# In base command class Lister in cliff, abstract method take_action()
|
2016-02-06 10:30:34 +08:00
|
|
|
# returns a tuple containing the column names and an iterable
|
|
|
|
# containing the data to be listed.
|
2015-01-30 13:04:45 -08:00
|
|
|
columns, data = self.cmd.take_action(parsed_args)
|
|
|
|
|
|
|
|
# Set expected values
|
|
|
|
kwargs = {
|
2015-10-14 11:05:02 +08:00
|
|
|
'is_public': True,
|
|
|
|
'limit': None,
|
|
|
|
'marker': None
|
2015-01-30 13:04:45 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
self.flavors_mock.list.assert_called_with(
|
|
|
|
**kwargs
|
|
|
|
)
|
|
|
|
|
2015-11-28 14:05:20 +08:00
|
|
|
self.assertEqual(self.columns, columns)
|
2015-11-28 14:26:09 +08:00
|
|
|
self.assertEqual(tuple(self.data), tuple(data))
|
2015-01-30 13:04:45 -08:00
|
|
|
|
|
|
|
def test_flavor_list_all_flavors(self):
|
|
|
|
arglist = [
|
|
|
|
'--all',
|
|
|
|
]
|
|
|
|
verifylist = [
|
|
|
|
('all', True),
|
|
|
|
]
|
|
|
|
|
|
|
|
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
|
|
|
|
|
2016-02-10 19:01:52 +08:00
|
|
|
# In base command class Lister in cliff, abstract method take_action()
|
2016-02-06 10:30:34 +08:00
|
|
|
# returns a tuple containing the column names and an iterable
|
|
|
|
# containing the data to be listed.
|
2015-01-30 13:04:45 -08:00
|
|
|
columns, data = self.cmd.take_action(parsed_args)
|
|
|
|
|
|
|
|
# Set expected values
|
|
|
|
kwargs = {
|
2015-10-14 11:05:02 +08:00
|
|
|
'is_public': None,
|
|
|
|
'limit': None,
|
|
|
|
'marker': None
|
2015-01-30 13:04:45 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
self.flavors_mock.list.assert_called_with(
|
|
|
|
**kwargs
|
|
|
|
)
|
|
|
|
|
2015-11-28 14:05:20 +08:00
|
|
|
self.assertEqual(self.columns, columns)
|
2015-11-28 14:26:09 +08:00
|
|
|
self.assertEqual(tuple(self.data), tuple(data))
|
2015-01-30 13:04:45 -08:00
|
|
|
|
|
|
|
def test_flavor_list_private_flavors(self):
|
|
|
|
arglist = [
|
|
|
|
'--private',
|
2015-12-08 13:35:51 +08:00
|
|
|
]
|
2015-01-30 13:04:45 -08:00
|
|
|
verifylist = [
|
|
|
|
('public', False),
|
2015-12-08 13:35:51 +08:00
|
|
|
]
|
2015-01-30 13:04:45 -08:00
|
|
|
|
|
|
|
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
|
|
|
|
|
2016-02-10 19:01:52 +08:00
|
|
|
# In base command class Lister in cliff, abstract method take_action()
|
2016-02-06 10:30:34 +08:00
|
|
|
# returns a tuple containing the column names and an iterable
|
|
|
|
# containing the data to be listed.
|
2015-01-30 13:04:45 -08:00
|
|
|
columns, data = self.cmd.take_action(parsed_args)
|
|
|
|
|
|
|
|
# Set expected values
|
|
|
|
kwargs = {
|
2015-10-14 11:05:02 +08:00
|
|
|
'is_public': False,
|
|
|
|
'limit': None,
|
|
|
|
'marker': None
|
2015-01-30 13:04:45 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
self.flavors_mock.list.assert_called_with(
|
|
|
|
**kwargs
|
|
|
|
)
|
|
|
|
|
2015-11-28 14:05:20 +08:00
|
|
|
self.assertEqual(self.columns, columns)
|
2015-11-28 14:26:09 +08:00
|
|
|
self.assertEqual(tuple(self.data), tuple(data))
|
2015-01-30 13:04:45 -08:00
|
|
|
|
|
|
|
def test_flavor_list_public_flavors(self):
|
|
|
|
arglist = [
|
|
|
|
'--public',
|
2015-12-08 13:35:51 +08:00
|
|
|
]
|
2015-01-30 13:04:45 -08:00
|
|
|
verifylist = [
|
|
|
|
('public', True),
|
2015-12-08 13:35:51 +08:00
|
|
|
]
|
2015-01-30 13:04:45 -08:00
|
|
|
|
|
|
|
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
|
|
|
|
|
2016-02-10 19:01:52 +08:00
|
|
|
# In base command class Lister in cliff, abstract method take_action()
|
2016-02-06 10:30:34 +08:00
|
|
|
# returns a tuple containing the column names and an iterable
|
|
|
|
# containing the data to be listed.
|
2015-01-30 13:04:45 -08:00
|
|
|
columns, data = self.cmd.take_action(parsed_args)
|
|
|
|
|
|
|
|
# Set expected values
|
|
|
|
kwargs = {
|
2015-10-14 11:05:02 +08:00
|
|
|
'is_public': True,
|
|
|
|
'limit': None,
|
|
|
|
'marker': None
|
2015-01-30 13:04:45 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
self.flavors_mock.list.assert_called_with(
|
|
|
|
**kwargs
|
|
|
|
)
|
|
|
|
|
2015-11-28 14:05:20 +08:00
|
|
|
self.assertEqual(self.columns, columns)
|
2015-11-28 14:26:09 +08:00
|
|
|
self.assertEqual(tuple(self.data), tuple(data))
|
2015-01-30 13:04:45 -08:00
|
|
|
|
|
|
|
def test_flavor_list_long(self):
|
|
|
|
arglist = [
|
|
|
|
'--long',
|
|
|
|
]
|
|
|
|
verifylist = [
|
|
|
|
('long', True),
|
|
|
|
]
|
|
|
|
|
|
|
|
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
|
|
|
|
|
2016-02-10 19:01:52 +08:00
|
|
|
# In base command class Lister in cliff, abstract method take_action()
|
2016-02-06 10:30:34 +08:00
|
|
|
# returns a tuple containing the column names and an iterable
|
|
|
|
# containing the data to be listed.
|
2015-01-30 13:04:45 -08:00
|
|
|
columns, data = self.cmd.take_action(parsed_args)
|
|
|
|
|
|
|
|
# Set expected values
|
|
|
|
kwargs = {
|
2015-10-14 11:05:02 +08:00
|
|
|
'is_public': True,
|
|
|
|
'limit': None,
|
|
|
|
'marker': None
|
2015-01-30 13:04:45 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
self.flavors_mock.list.assert_called_with(
|
|
|
|
**kwargs
|
|
|
|
)
|
|
|
|
|
2015-11-28 14:05:20 +08:00
|
|
|
self.assertEqual(self.columns_long, columns)
|
2020-11-02 13:25:59 +01:00
|
|
|
self.assertListItemEqual(self.data_long, tuple(data))
|
2015-03-17 15:38:24 +01:00
|
|
|
|
|
|
|
|
|
|
|
class TestFlavorSet(TestFlavor):
|
|
|
|
|
2015-11-28 16:05:14 +08:00
|
|
|
# Return value of self.flavors_mock.find().
|
2016-05-26 20:00:12 +08:00
|
|
|
flavor = compute_fakes.FakeFlavor.create_one_flavor(
|
|
|
|
attrs={'os-flavor-access:is_public': False})
|
2016-07-15 19:02:18 +08:00
|
|
|
project = identity_fakes.FakeProject.create_one_project()
|
2015-11-28 16:05:14 +08:00
|
|
|
|
2015-03-17 15:38:24 +01:00
|
|
|
def setUp(self):
|
|
|
|
super(TestFlavorSet, self).setUp()
|
|
|
|
|
2015-11-28 16:05:14 +08:00
|
|
|
self.flavors_mock.find.return_value = self.flavor
|
Make "flavor show" command to show a private flavor properly
The "flavor show" command could not show a
private flavor by flavor name becauce it could
not find a private flavor by flavor name.
In "until.find_resource(parsed_args.flavor)",
If parsed_args.falvor is a name of a flavor,
"flavors.find(name=parsed_args.flavor)"will be
called to find a flavor.But the default value of
"is_public" is "Ture" in "flavors.find()" so that
we can only find public flavors.If we want to find
all flaovrs by flavor name,we should add
"is_public=None" in "flavors.find()".
So I tried to change
"until.find_resource(parsed_args.flavor)" to
"until.find_resource(parsed_args.flavor, is_public=None)",
but then I could not find any flavor by flavor id
because "is_public" is an unexpected argument of
"flavors.get()" in "until.find_resource()".
In this case,I think "until.find_resource()"
can not find a private flavor properly,and
we should combine "manager.get(flavor.id)" and
"manager.find(name=flavor.name, is_public=None)"
by ourselve to find a flavor.
Also,this bug affects other flavor commands like
"flavor set/unset/delete",so I fix them in this patch too.
Change-Id: I4a4ed7b0a2f522ee04d1c3270afcda7064285c39
Closes-Bug: #1575478
2016-05-02 16:30:29 +08:00
|
|
|
self.flavors_mock.get.side_effect = exceptions.NotFound(None)
|
2016-05-26 20:00:12 +08:00
|
|
|
# Return a project
|
2016-07-15 19:02:18 +08:00
|
|
|
self.projects_mock.get.return_value = self.project
|
2015-03-17 15:38:24 +01:00
|
|
|
self.cmd = flavor.SetFlavor(self.app, None)
|
|
|
|
|
2016-05-26 20:00:12 +08:00
|
|
|
def test_flavor_set_property(self):
|
2015-03-17 15:38:24 +01:00
|
|
|
arglist = [
|
|
|
|
'--property', 'FOO="B A R"',
|
|
|
|
'baremetal'
|
|
|
|
]
|
|
|
|
verifylist = [
|
|
|
|
('property', {'FOO': '"B A R"'}),
|
|
|
|
('flavor', 'baremetal')
|
|
|
|
]
|
|
|
|
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
|
|
|
|
|
2016-02-17 10:07:50 +08:00
|
|
|
result = self.cmd.take_action(parsed_args)
|
Make "flavor show" command to show a private flavor properly
The "flavor show" command could not show a
private flavor by flavor name becauce it could
not find a private flavor by flavor name.
In "until.find_resource(parsed_args.flavor)",
If parsed_args.falvor is a name of a flavor,
"flavors.find(name=parsed_args.flavor)"will be
called to find a flavor.But the default value of
"is_public" is "Ture" in "flavors.find()" so that
we can only find public flavors.If we want to find
all flaovrs by flavor name,we should add
"is_public=None" in "flavors.find()".
So I tried to change
"until.find_resource(parsed_args.flavor)" to
"until.find_resource(parsed_args.flavor, is_public=None)",
but then I could not find any flavor by flavor id
because "is_public" is an unexpected argument of
"flavors.get()" in "until.find_resource()".
In this case,I think "until.find_resource()"
can not find a private flavor properly,and
we should combine "manager.get(flavor.id)" and
"manager.find(name=flavor.name, is_public=None)"
by ourselve to find a flavor.
Also,this bug affects other flavor commands like
"flavor set/unset/delete",so I fix them in this patch too.
Change-Id: I4a4ed7b0a2f522ee04d1c3270afcda7064285c39
Closes-Bug: #1575478
2016-05-02 16:30:29 +08:00
|
|
|
self.flavors_mock.find.assert_called_with(name=parsed_args.flavor,
|
|
|
|
is_public=None)
|
2016-06-14 14:51:37 +08:00
|
|
|
self.flavor.set_keys.assert_called_with({'FOO': '"B A R"'})
|
2016-02-17 10:07:50 +08:00
|
|
|
self.assertIsNone(result)
|
2016-02-20 10:34:40 +08:00
|
|
|
|
2016-12-28 01:45:42 -05:00
|
|
|
def test_flavor_set_no_property(self):
|
|
|
|
arglist = [
|
|
|
|
'--no-property',
|
|
|
|
'baremetal'
|
|
|
|
]
|
|
|
|
verifylist = [
|
|
|
|
('no_property', True),
|
|
|
|
('flavor', 'baremetal')
|
|
|
|
]
|
|
|
|
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
|
|
|
|
|
|
|
|
result = self.cmd.take_action(parsed_args)
|
|
|
|
self.flavors_mock.find.assert_called_with(name=parsed_args.flavor,
|
|
|
|
is_public=None)
|
|
|
|
self.flavor.unset_keys.assert_called_with(['property'])
|
|
|
|
self.assertIsNone(result)
|
|
|
|
|
2016-05-26 20:00:12 +08:00
|
|
|
def test_flavor_set_project(self):
|
|
|
|
arglist = [
|
2016-07-15 19:02:18 +08:00
|
|
|
'--project', self.project.id,
|
2016-05-26 20:00:12 +08:00
|
|
|
self.flavor.id,
|
|
|
|
]
|
|
|
|
verifylist = [
|
2016-07-15 19:02:18 +08:00
|
|
|
('project', self.project.id),
|
2016-05-26 20:00:12 +08:00
|
|
|
('flavor', self.flavor.id),
|
|
|
|
]
|
|
|
|
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
|
|
|
|
|
|
|
|
result = self.cmd.take_action(parsed_args)
|
|
|
|
|
2016-06-14 14:51:37 +08:00
|
|
|
self.flavors_mock.find.assert_called_with(name=parsed_args.flavor,
|
|
|
|
is_public=None)
|
2016-05-26 20:00:12 +08:00
|
|
|
self.flavor_access_mock.add_tenant_access.assert_called_with(
|
|
|
|
self.flavor.id,
|
2016-07-15 19:02:18 +08:00
|
|
|
self.project.id,
|
2016-05-26 20:00:12 +08:00
|
|
|
)
|
2016-06-14 14:51:37 +08:00
|
|
|
self.flavor.set_keys.assert_not_called()
|
|
|
|
self.assertIsNone(result)
|
2016-05-26 20:00:12 +08:00
|
|
|
|
|
|
|
def test_flavor_set_no_project(self):
|
|
|
|
arglist = [
|
2016-06-03 15:53:49 +08:00
|
|
|
'--project',
|
2016-05-26 20:00:12 +08:00
|
|
|
self.flavor.id,
|
|
|
|
]
|
|
|
|
verifylist = [
|
2016-06-14 14:51:37 +08:00
|
|
|
('project', None),
|
2016-05-26 20:00:12 +08:00
|
|
|
('flavor', self.flavor.id),
|
|
|
|
]
|
2016-06-03 15:53:49 +08:00
|
|
|
self.assertRaises(tests_utils.ParserException, self.check_parser,
|
|
|
|
self.cmd, arglist, verifylist)
|
2016-05-26 20:00:12 +08:00
|
|
|
|
|
|
|
def test_flavor_set_no_flavor(self):
|
|
|
|
arglist = [
|
2016-07-15 19:02:18 +08:00
|
|
|
'--project', self.project.id,
|
2016-05-26 20:00:12 +08:00
|
|
|
]
|
|
|
|
verifylist = [
|
2016-07-15 19:02:18 +08:00
|
|
|
('project', self.project.id),
|
2016-05-26 20:00:12 +08:00
|
|
|
]
|
2016-06-14 14:51:37 +08:00
|
|
|
self.assertRaises(tests_utils.ParserException, self.check_parser,
|
|
|
|
self.cmd, arglist, verifylist)
|
2016-05-26 20:00:12 +08:00
|
|
|
|
|
|
|
def test_flavor_set_with_unexist_flavor(self):
|
|
|
|
self.flavors_mock.get.side_effect = exceptions.NotFound(None)
|
|
|
|
self.flavors_mock.find.side_effect = exceptions.NotFound(None)
|
|
|
|
|
|
|
|
arglist = [
|
2016-07-15 19:02:18 +08:00
|
|
|
'--project', self.project.id,
|
2016-05-26 20:00:12 +08:00
|
|
|
'unexist_flavor',
|
|
|
|
]
|
|
|
|
verifylist = [
|
2016-07-15 19:02:18 +08:00
|
|
|
('project', self.project.id),
|
2016-05-26 20:00:12 +08:00
|
|
|
('flavor', 'unexist_flavor'),
|
|
|
|
]
|
|
|
|
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
|
|
|
|
|
|
|
|
self.assertRaises(exceptions.CommandError,
|
|
|
|
self.cmd.take_action,
|
|
|
|
parsed_args)
|
|
|
|
|
|
|
|
def test_flavor_set_nothing(self):
|
|
|
|
arglist = [
|
|
|
|
self.flavor.id,
|
|
|
|
]
|
|
|
|
verifylist = [
|
|
|
|
('flavor', self.flavor.id),
|
|
|
|
]
|
|
|
|
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
|
2016-06-21 15:15:18 +08:00
|
|
|
result = self.cmd.take_action(parsed_args)
|
|
|
|
|
|
|
|
self.flavors_mock.find.assert_called_with(name=parsed_args.flavor,
|
|
|
|
is_public=None)
|
|
|
|
self.flavor_access_mock.add_tenant_access.assert_not_called()
|
|
|
|
self.assertIsNone(result)
|
2016-05-26 20:00:12 +08:00
|
|
|
|
2018-06-14 18:20:04 +08:00
|
|
|
def test_flavor_set_description_api_newer(self):
|
|
|
|
arglist = [
|
|
|
|
'--description', 'description',
|
|
|
|
self.flavor.id,
|
|
|
|
]
|
|
|
|
verifylist = [
|
|
|
|
('description', 'description'),
|
|
|
|
('flavor', self.flavor.id),
|
|
|
|
]
|
|
|
|
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
|
|
|
|
self.app.client_manager.compute.api_version = 2.55
|
|
|
|
with mock.patch.object(novaclient.api_versions,
|
|
|
|
'APIVersion',
|
|
|
|
return_value=2.55):
|
|
|
|
result = self.cmd.take_action(parsed_args)
|
|
|
|
self.flavors_mock.update.assert_called_with(
|
|
|
|
flavor=self.flavor.id, description='description')
|
|
|
|
self.assertIsNone(result)
|
|
|
|
|
|
|
|
def test_flavor_set_description_api_older(self):
|
|
|
|
arglist = [
|
|
|
|
'--description', 'description',
|
|
|
|
self.flavor.id,
|
|
|
|
]
|
|
|
|
verifylist = [
|
|
|
|
('description', 'description'),
|
|
|
|
('flavor', self.flavor.id),
|
|
|
|
]
|
|
|
|
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
|
|
|
|
self.app.client_manager.compute.api_version = 2.54
|
2020-06-04 12:46:25 -07:00
|
|
|
with mock.patch.object(novaclient.api_versions,
|
|
|
|
'APIVersion',
|
|
|
|
return_value=2.55):
|
|
|
|
self.assertRaises(exceptions.CommandError, self.cmd.take_action,
|
|
|
|
parsed_args)
|
|
|
|
|
|
|
|
def test_flavor_set_description_using_name_api_newer(self):
|
|
|
|
arglist = [
|
|
|
|
'--description', 'description',
|
|
|
|
self.flavor.name,
|
|
|
|
]
|
|
|
|
verifylist = [
|
|
|
|
('description', 'description'),
|
|
|
|
('flavor', self.flavor.name),
|
|
|
|
]
|
|
|
|
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
|
|
|
|
self.app.client_manager.compute.api_version = 2.55
|
|
|
|
with mock.patch.object(novaclient.api_versions,
|
|
|
|
'APIVersion',
|
|
|
|
return_value=2.55):
|
|
|
|
result = self.cmd.take_action(parsed_args)
|
|
|
|
self.flavors_mock.update.assert_called_with(
|
|
|
|
flavor=self.flavor.id, description='description')
|
|
|
|
self.assertIsNone(result)
|
|
|
|
|
|
|
|
def test_flavor_set_description_using_name_api_older(self):
|
|
|
|
arglist = [
|
|
|
|
'--description', 'description',
|
|
|
|
self.flavor.name,
|
|
|
|
]
|
|
|
|
verifylist = [
|
|
|
|
('description', 'description'),
|
|
|
|
('flavor', self.flavor.name),
|
|
|
|
]
|
|
|
|
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
|
|
|
|
self.app.client_manager.compute.api_version = 2.54
|
2018-06-14 18:20:04 +08:00
|
|
|
with mock.patch.object(novaclient.api_versions,
|
|
|
|
'APIVersion',
|
|
|
|
return_value=2.55):
|
|
|
|
self.assertRaises(exceptions.CommandError, self.cmd.take_action,
|
|
|
|
parsed_args)
|
|
|
|
|
2016-02-20 10:34:40 +08:00
|
|
|
|
|
|
|
class TestFlavorShow(TestFlavor):
|
|
|
|
|
|
|
|
# Return value of self.flavors_mock.find().
|
2016-07-07 21:27:22 +08:00
|
|
|
flavor_access = compute_fakes.FakeFlavorAccess.create_one_flavor_access()
|
2016-02-20 10:34:40 +08:00
|
|
|
flavor = compute_fakes.FakeFlavor.create_one_flavor()
|
|
|
|
|
|
|
|
columns = (
|
|
|
|
'OS-FLV-DISABLED:disabled',
|
|
|
|
'OS-FLV-EXT-DATA:ephemeral',
|
2016-07-07 21:27:22 +08:00
|
|
|
'access_project_ids',
|
2018-06-14 18:20:04 +08:00
|
|
|
'description',
|
2016-02-20 10:34:40 +08:00
|
|
|
'disk',
|
|
|
|
'id',
|
|
|
|
'name',
|
|
|
|
'os-flavor-access:is_public',
|
|
|
|
'properties',
|
|
|
|
'ram',
|
|
|
|
'rxtx_factor',
|
|
|
|
'swap',
|
|
|
|
'vcpus',
|
|
|
|
)
|
|
|
|
|
|
|
|
data = (
|
|
|
|
flavor.disabled,
|
|
|
|
flavor.ephemeral,
|
2016-07-07 21:27:22 +08:00
|
|
|
None,
|
2018-06-14 18:20:04 +08:00
|
|
|
flavor.description,
|
2016-02-20 10:34:40 +08:00
|
|
|
flavor.disk,
|
|
|
|
flavor.id,
|
|
|
|
flavor.name,
|
|
|
|
flavor.is_public,
|
2020-11-02 13:25:59 +01:00
|
|
|
format_columns.DictColumn(flavor.get_keys()),
|
2016-02-20 10:34:40 +08:00
|
|
|
flavor.ram,
|
|
|
|
flavor.rxtx_factor,
|
|
|
|
flavor.swap,
|
|
|
|
flavor.vcpus,
|
|
|
|
)
|
|
|
|
|
|
|
|
def setUp(self):
|
|
|
|
super(TestFlavorShow, self).setUp()
|
|
|
|
|
Make "flavor show" command to show a private flavor properly
The "flavor show" command could not show a
private flavor by flavor name becauce it could
not find a private flavor by flavor name.
In "until.find_resource(parsed_args.flavor)",
If parsed_args.falvor is a name of a flavor,
"flavors.find(name=parsed_args.flavor)"will be
called to find a flavor.But the default value of
"is_public" is "Ture" in "flavors.find()" so that
we can only find public flavors.If we want to find
all flaovrs by flavor name,we should add
"is_public=None" in "flavors.find()".
So I tried to change
"until.find_resource(parsed_args.flavor)" to
"until.find_resource(parsed_args.flavor, is_public=None)",
but then I could not find any flavor by flavor id
because "is_public" is an unexpected argument of
"flavors.get()" in "until.find_resource()".
In this case,I think "until.find_resource()"
can not find a private flavor properly,and
we should combine "manager.get(flavor.id)" and
"manager.find(name=flavor.name, is_public=None)"
by ourselve to find a flavor.
Also,this bug affects other flavor commands like
"flavor set/unset/delete",so I fix them in this patch too.
Change-Id: I4a4ed7b0a2f522ee04d1c3270afcda7064285c39
Closes-Bug: #1575478
2016-05-02 16:30:29 +08:00
|
|
|
# Return value of _find_resource()
|
|
|
|
self.flavors_mock.find.return_value = self.flavor
|
|
|
|
self.flavors_mock.get.side_effect = exceptions.NotFound(None)
|
2016-07-07 21:27:22 +08:00
|
|
|
self.flavor_access_mock.list.return_value = [self.flavor_access]
|
2016-02-20 10:34:40 +08:00
|
|
|
self.cmd = flavor.ShowFlavor(self.app, None)
|
|
|
|
|
|
|
|
def test_show_no_options(self):
|
|
|
|
arglist = []
|
|
|
|
verifylist = []
|
|
|
|
|
|
|
|
# Missing required args should boil here
|
|
|
|
self.assertRaises(tests_utils.ParserException, self.check_parser,
|
|
|
|
self.cmd, arglist, verifylist)
|
|
|
|
|
2016-07-07 21:27:22 +08:00
|
|
|
def test_public_flavor_show(self):
|
2016-02-20 10:34:40 +08:00
|
|
|
arglist = [
|
|
|
|
self.flavor.name,
|
|
|
|
]
|
|
|
|
verifylist = [
|
|
|
|
('flavor', self.flavor.name),
|
|
|
|
]
|
|
|
|
|
|
|
|
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
|
|
|
|
|
|
|
|
columns, data = self.cmd.take_action(parsed_args)
|
|
|
|
|
|
|
|
self.assertEqual(self.columns, columns)
|
2020-11-02 13:25:59 +01:00
|
|
|
self.assertItemEqual(self.data, data)
|
2015-03-17 15:38:24 +01:00
|
|
|
|
2016-07-07 21:27:22 +08:00
|
|
|
def test_private_flavor_show(self):
|
|
|
|
private_flavor = compute_fakes.FakeFlavor.create_one_flavor(
|
|
|
|
attrs={
|
|
|
|
'os-flavor-access:is_public': False,
|
|
|
|
}
|
|
|
|
)
|
|
|
|
self.flavors_mock.find.return_value = private_flavor
|
|
|
|
|
|
|
|
arglist = [
|
|
|
|
private_flavor.name,
|
|
|
|
]
|
|
|
|
verifylist = [
|
|
|
|
('flavor', private_flavor.name),
|
|
|
|
]
|
|
|
|
|
|
|
|
data_with_project = (
|
|
|
|
private_flavor.disabled,
|
|
|
|
private_flavor.ephemeral,
|
2020-11-02 13:25:59 +01:00
|
|
|
[self.flavor_access.tenant_id],
|
2018-06-14 18:20:04 +08:00
|
|
|
private_flavor.description,
|
2016-07-07 21:27:22 +08:00
|
|
|
private_flavor.disk,
|
|
|
|
private_flavor.id,
|
|
|
|
private_flavor.name,
|
|
|
|
private_flavor.is_public,
|
2020-11-02 13:25:59 +01:00
|
|
|
format_columns.DictColumn(private_flavor.get_keys()),
|
2016-07-07 21:27:22 +08:00
|
|
|
private_flavor.ram,
|
|
|
|
private_flavor.rxtx_factor,
|
|
|
|
private_flavor.swap,
|
|
|
|
private_flavor.vcpus,
|
|
|
|
)
|
|
|
|
|
|
|
|
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
|
|
|
|
|
|
|
|
columns, data = self.cmd.take_action(parsed_args)
|
|
|
|
|
|
|
|
self.flavor_access_mock.list.assert_called_with(
|
|
|
|
flavor=private_flavor.id)
|
|
|
|
self.assertEqual(self.columns, columns)
|
2020-11-02 13:25:59 +01:00
|
|
|
self.assertItemEqual(data_with_project, data)
|
2016-07-07 21:27:22 +08:00
|
|
|
|
2015-03-17 15:38:24 +01:00
|
|
|
|
|
|
|
class TestFlavorUnset(TestFlavor):
|
|
|
|
|
2015-11-28 16:09:01 +08:00
|
|
|
# Return value of self.flavors_mock.find().
|
2016-06-01 09:42:40 +08:00
|
|
|
flavor = compute_fakes.FakeFlavor.create_one_flavor(
|
|
|
|
attrs={'os-flavor-access:is_public': False})
|
2016-07-15 19:02:18 +08:00
|
|
|
project = identity_fakes.FakeProject.create_one_project()
|
2015-11-28 16:09:01 +08:00
|
|
|
|
2015-03-17 15:38:24 +01:00
|
|
|
def setUp(self):
|
|
|
|
super(TestFlavorUnset, self).setUp()
|
|
|
|
|
2015-11-28 16:09:01 +08:00
|
|
|
self.flavors_mock.find.return_value = self.flavor
|
Make "flavor show" command to show a private flavor properly
The "flavor show" command could not show a
private flavor by flavor name becauce it could
not find a private flavor by flavor name.
In "until.find_resource(parsed_args.flavor)",
If parsed_args.falvor is a name of a flavor,
"flavors.find(name=parsed_args.flavor)"will be
called to find a flavor.But the default value of
"is_public" is "Ture" in "flavors.find()" so that
we can only find public flavors.If we want to find
all flaovrs by flavor name,we should add
"is_public=None" in "flavors.find()".
So I tried to change
"until.find_resource(parsed_args.flavor)" to
"until.find_resource(parsed_args.flavor, is_public=None)",
but then I could not find any flavor by flavor id
because "is_public" is an unexpected argument of
"flavors.get()" in "until.find_resource()".
In this case,I think "until.find_resource()"
can not find a private flavor properly,and
we should combine "manager.get(flavor.id)" and
"manager.find(name=flavor.name, is_public=None)"
by ourselve to find a flavor.
Also,this bug affects other flavor commands like
"flavor set/unset/delete",so I fix them in this patch too.
Change-Id: I4a4ed7b0a2f522ee04d1c3270afcda7064285c39
Closes-Bug: #1575478
2016-05-02 16:30:29 +08:00
|
|
|
self.flavors_mock.get.side_effect = exceptions.NotFound(None)
|
2016-06-01 09:42:40 +08:00
|
|
|
# Return a project
|
2016-07-15 19:02:18 +08:00
|
|
|
self.projects_mock.get.return_value = self.project
|
2015-03-17 15:38:24 +01:00
|
|
|
self.cmd = flavor.UnsetFlavor(self.app, None)
|
|
|
|
|
2016-06-01 09:42:40 +08:00
|
|
|
def test_flavor_unset_property(self):
|
2015-03-17 15:38:24 +01:00
|
|
|
arglist = [
|
|
|
|
'--property', 'property',
|
|
|
|
'baremetal'
|
|
|
|
]
|
|
|
|
verifylist = [
|
|
|
|
('property', ['property']),
|
|
|
|
('flavor', 'baremetal'),
|
|
|
|
]
|
|
|
|
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
|
|
|
|
|
2016-02-17 10:07:50 +08:00
|
|
|
result = self.cmd.take_action(parsed_args)
|
Make "flavor show" command to show a private flavor properly
The "flavor show" command could not show a
private flavor by flavor name becauce it could
not find a private flavor by flavor name.
In "until.find_resource(parsed_args.flavor)",
If parsed_args.falvor is a name of a flavor,
"flavors.find(name=parsed_args.flavor)"will be
called to find a flavor.But the default value of
"is_public" is "Ture" in "flavors.find()" so that
we can only find public flavors.If we want to find
all flaovrs by flavor name,we should add
"is_public=None" in "flavors.find()".
So I tried to change
"until.find_resource(parsed_args.flavor)" to
"until.find_resource(parsed_args.flavor, is_public=None)",
but then I could not find any flavor by flavor id
because "is_public" is an unexpected argument of
"flavors.get()" in "until.find_resource()".
In this case,I think "until.find_resource()"
can not find a private flavor properly,and
we should combine "manager.get(flavor.id)" and
"manager.find(name=flavor.name, is_public=None)"
by ourselve to find a flavor.
Also,this bug affects other flavor commands like
"flavor set/unset/delete",so I fix them in this patch too.
Change-Id: I4a4ed7b0a2f522ee04d1c3270afcda7064285c39
Closes-Bug: #1575478
2016-05-02 16:30:29 +08:00
|
|
|
self.flavors_mock.find.assert_called_with(name=parsed_args.flavor,
|
|
|
|
is_public=None)
|
2016-06-13 19:19:19 +08:00
|
|
|
self.flavor.unset_keys.assert_called_with(['property'])
|
|
|
|
self.flavor_access_mock.remove_tenant_access.assert_not_called()
|
2016-02-17 10:07:50 +08:00
|
|
|
self.assertIsNone(result)
|
2016-06-01 09:42:40 +08:00
|
|
|
|
|
|
|
def test_flavor_unset_project(self):
|
|
|
|
arglist = [
|
2016-07-15 19:02:18 +08:00
|
|
|
'--project', self.project.id,
|
2016-06-01 09:42:40 +08:00
|
|
|
self.flavor.id,
|
|
|
|
]
|
|
|
|
verifylist = [
|
2016-07-15 19:02:18 +08:00
|
|
|
('project', self.project.id),
|
2016-06-01 09:42:40 +08:00
|
|
|
('flavor', self.flavor.id),
|
|
|
|
]
|
|
|
|
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
|
|
|
|
|
|
|
|
result = self.cmd.take_action(parsed_args)
|
|
|
|
self.assertIsNone(result)
|
|
|
|
|
2016-06-13 19:19:19 +08:00
|
|
|
self.flavors_mock.find.assert_called_with(name=parsed_args.flavor,
|
|
|
|
is_public=None)
|
2016-06-01 09:42:40 +08:00
|
|
|
self.flavor_access_mock.remove_tenant_access.assert_called_with(
|
|
|
|
self.flavor.id,
|
2016-07-15 19:02:18 +08:00
|
|
|
self.project.id,
|
2016-06-01 09:42:40 +08:00
|
|
|
)
|
2016-06-13 19:19:19 +08:00
|
|
|
self.flavor.unset_keys.assert_not_called()
|
|
|
|
self.assertIsNone(result)
|
2016-06-01 09:42:40 +08:00
|
|
|
|
2016-06-14 14:51:37 +08:00
|
|
|
def test_flavor_unset_no_project(self):
|
|
|
|
arglist = [
|
|
|
|
'--project',
|
|
|
|
self.flavor.id,
|
|
|
|
]
|
|
|
|
verifylist = [
|
|
|
|
('project', None),
|
|
|
|
('flavor', self.flavor.id),
|
|
|
|
]
|
|
|
|
self.assertRaises(tests_utils.ParserException, self.check_parser,
|
|
|
|
self.cmd, arglist, verifylist)
|
|
|
|
|
2016-06-01 09:42:40 +08:00
|
|
|
def test_flavor_unset_no_flavor(self):
|
|
|
|
arglist = [
|
2016-07-15 19:02:18 +08:00
|
|
|
'--project', self.project.id,
|
2016-06-01 09:42:40 +08:00
|
|
|
]
|
|
|
|
verifylist = [
|
2016-07-15 19:02:18 +08:00
|
|
|
('project', self.project.id),
|
2016-06-01 09:42:40 +08:00
|
|
|
]
|
2016-06-13 19:19:19 +08:00
|
|
|
self.assertRaises(tests_utils.ParserException, self.check_parser,
|
|
|
|
self.cmd, arglist, verifylist)
|
2016-06-01 09:42:40 +08:00
|
|
|
|
|
|
|
def test_flavor_unset_with_unexist_flavor(self):
|
|
|
|
self.flavors_mock.get.side_effect = exceptions.NotFound(None)
|
|
|
|
self.flavors_mock.find.side_effect = exceptions.NotFound(None)
|
|
|
|
|
|
|
|
arglist = [
|
2016-07-15 19:02:18 +08:00
|
|
|
'--project', self.project.id,
|
2016-06-01 09:42:40 +08:00
|
|
|
'unexist_flavor',
|
|
|
|
]
|
|
|
|
verifylist = [
|
2016-07-15 19:02:18 +08:00
|
|
|
('project', self.project.id),
|
2016-06-01 09:42:40 +08:00
|
|
|
('flavor', 'unexist_flavor'),
|
|
|
|
]
|
|
|
|
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
|
2016-06-13 19:19:19 +08:00
|
|
|
self.assertRaises(exceptions.CommandError, self.cmd.take_action,
|
2016-06-01 09:42:40 +08:00
|
|
|
parsed_args)
|
|
|
|
|
|
|
|
def test_flavor_unset_nothing(self):
|
|
|
|
arglist = [
|
|
|
|
self.flavor.id,
|
|
|
|
]
|
|
|
|
verifylist = [
|
|
|
|
('flavor', self.flavor.id),
|
|
|
|
]
|
|
|
|
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
|
2016-06-21 15:15:18 +08:00
|
|
|
|
|
|
|
result = self.cmd.take_action(parsed_args)
|
|
|
|
self.assertIsNone(result)
|
|
|
|
|
|
|
|
self.flavor_access_mock.remove_tenant_access.assert_not_called()
|