Merge "Add host and hypervisor_hostname to create servers"
This commit is contained in:
commit
c474319909
@ -100,7 +100,7 @@ python-mimeparse==1.6.0
|
|||||||
python-mistralclient==3.1.0
|
python-mistralclient==3.1.0
|
||||||
python-muranoclient==0.8.2
|
python-muranoclient==0.8.2
|
||||||
python-neutronclient==6.7.0
|
python-neutronclient==6.7.0
|
||||||
python-novaclient==14.1.0
|
python-novaclient==14.2.0
|
||||||
python-octaviaclient==1.3.0
|
python-octaviaclient==1.3.0
|
||||||
python-rsdclient==0.1.0
|
python-rsdclient==0.1.0
|
||||||
python-saharaclient==1.4.0
|
python-saharaclient==1.4.0
|
||||||
|
@ -553,6 +553,20 @@ class CreateServer(command.ShowOne):
|
|||||||
metavar='<zone-name>',
|
metavar='<zone-name>',
|
||||||
help=_('Select an availability zone for the server'),
|
help=_('Select an availability zone for the server'),
|
||||||
)
|
)
|
||||||
|
parser.add_argument(
|
||||||
|
'--host',
|
||||||
|
metavar='<host>',
|
||||||
|
help=_('Requested host to create servers. Admin only '
|
||||||
|
'by default. (supported by --os-compute-api-version 2.74 '
|
||||||
|
'or above)'),
|
||||||
|
)
|
||||||
|
parser.add_argument(
|
||||||
|
'--hypervisor-hostname',
|
||||||
|
metavar='<hypervisor-hostname>',
|
||||||
|
help=_('Requested hypervisor hostname to create servers. Admin '
|
||||||
|
'only by default. (supported by --os-compute-api-version '
|
||||||
|
'2.74 or above)'),
|
||||||
|
)
|
||||||
parser.add_argument(
|
parser.add_argument(
|
||||||
'--block-device-mapping',
|
'--block-device-mapping',
|
||||||
metavar='<dev-name=mapping>',
|
metavar='<dev-name=mapping>',
|
||||||
@ -927,6 +941,21 @@ class CreateServer(command.ShowOne):
|
|||||||
if parsed_args.description:
|
if parsed_args.description:
|
||||||
boot_kwargs['description'] = parsed_args.description
|
boot_kwargs['description'] = parsed_args.description
|
||||||
|
|
||||||
|
if parsed_args.host:
|
||||||
|
if compute_client.api_version < api_versions.APIVersion("2.74"):
|
||||||
|
msg = _("Specifying --host is not supported for "
|
||||||
|
"--os-compute-api-version less than 2.74")
|
||||||
|
raise exceptions.CommandError(msg)
|
||||||
|
boot_kwargs['host'] = parsed_args.host
|
||||||
|
|
||||||
|
if parsed_args.hypervisor_hostname:
|
||||||
|
if compute_client.api_version < api_versions.APIVersion("2.74"):
|
||||||
|
msg = _("Specifying --hypervisor-hostname is not supported "
|
||||||
|
"for --os-compute-api-version less than 2.74")
|
||||||
|
raise exceptions.CommandError(msg)
|
||||||
|
boot_kwargs['hypervisor_hostname'] = (
|
||||||
|
parsed_args.hypervisor_hostname)
|
||||||
|
|
||||||
LOG.debug('boot_args: %s', boot_args)
|
LOG.debug('boot_args: %s', boot_args)
|
||||||
LOG.debug('boot_kwargs: %s', boot_kwargs)
|
LOG.debug('boot_kwargs: %s', boot_kwargs)
|
||||||
|
|
||||||
|
@ -1940,6 +1940,237 @@ class TestServerCreate(TestServer):
|
|||||||
self.assertRaises(exceptions.CommandError, self.cmd.take_action,
|
self.assertRaises(exceptions.CommandError, self.cmd.take_action,
|
||||||
parsed_args)
|
parsed_args)
|
||||||
|
|
||||||
|
def test_server_create_with_host_v274(self):
|
||||||
|
|
||||||
|
# Explicit host is supported for nova api version 2.74 or above
|
||||||
|
self.app.client_manager.compute.api_version = 2.74
|
||||||
|
|
||||||
|
arglist = [
|
||||||
|
'--image', 'image1',
|
||||||
|
'--flavor', 'flavor1',
|
||||||
|
'--host', 'host1',
|
||||||
|
self.new_server.name,
|
||||||
|
]
|
||||||
|
verifylist = [
|
||||||
|
('image', 'image1'),
|
||||||
|
('flavor', 'flavor1'),
|
||||||
|
('host', 'host1'),
|
||||||
|
('config_drive', False),
|
||||||
|
('server_name', self.new_server.name),
|
||||||
|
]
|
||||||
|
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
|
||||||
|
|
||||||
|
with mock.patch.object(api_versions,
|
||||||
|
'APIVersion',
|
||||||
|
return_value=2.74):
|
||||||
|
# In base command class ShowOne in cliff, abstract method
|
||||||
|
# take_action() returns a two-part tuple with a tuple of
|
||||||
|
# column names and a tuple of data to be shown.
|
||||||
|
columns, data = self.cmd.take_action(parsed_args)
|
||||||
|
|
||||||
|
# Set expected values
|
||||||
|
kwargs = dict(
|
||||||
|
meta=None,
|
||||||
|
files={},
|
||||||
|
reservation_id=None,
|
||||||
|
min_count=1,
|
||||||
|
max_count=1,
|
||||||
|
security_groups=[],
|
||||||
|
userdata=None,
|
||||||
|
key_name=None,
|
||||||
|
availability_zone=None,
|
||||||
|
block_device_mapping_v2=[],
|
||||||
|
nics='auto',
|
||||||
|
scheduler_hints={},
|
||||||
|
config_drive=None,
|
||||||
|
host='host1',
|
||||||
|
)
|
||||||
|
# ServerManager.create(name, image, flavor, **kwargs)
|
||||||
|
self.servers_mock.create.assert_called_with(
|
||||||
|
self.new_server.name,
|
||||||
|
self.image,
|
||||||
|
self.flavor,
|
||||||
|
**kwargs
|
||||||
|
)
|
||||||
|
|
||||||
|
self.assertEqual(self.columns, columns)
|
||||||
|
self.assertEqual(self.datalist(), data)
|
||||||
|
self.assertFalse(self.images_mock.called)
|
||||||
|
self.assertFalse(self.flavors_mock.called)
|
||||||
|
|
||||||
|
def test_server_create_with_host_pre_v274(self):
|
||||||
|
|
||||||
|
# Host is not supported for nova api version below 2.74
|
||||||
|
self.app.client_manager.compute.api_version = 2.73
|
||||||
|
|
||||||
|
arglist = [
|
||||||
|
'--image', 'image1',
|
||||||
|
'--flavor', 'flavor1',
|
||||||
|
'--host', 'host1',
|
||||||
|
self.new_server.name,
|
||||||
|
]
|
||||||
|
verifylist = [
|
||||||
|
('image', 'image1'),
|
||||||
|
('flavor', 'flavor1'),
|
||||||
|
('host', 'host1'),
|
||||||
|
('config_drive', False),
|
||||||
|
('server_name', self.new_server.name),
|
||||||
|
]
|
||||||
|
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
|
||||||
|
|
||||||
|
with mock.patch.object(api_versions,
|
||||||
|
'APIVersion',
|
||||||
|
return_value=2.74):
|
||||||
|
self.assertRaises(exceptions.CommandError, self.cmd.take_action,
|
||||||
|
parsed_args)
|
||||||
|
|
||||||
|
def test_server_create_with_hypervisor_hostname_v274(self):
|
||||||
|
|
||||||
|
# Explicit hypervisor_hostname is supported for nova api version
|
||||||
|
# 2.74 or above
|
||||||
|
self.app.client_manager.compute.api_version = 2.74
|
||||||
|
|
||||||
|
arglist = [
|
||||||
|
'--image', 'image1',
|
||||||
|
'--flavor', 'flavor1',
|
||||||
|
'--hypervisor-hostname', 'node1',
|
||||||
|
self.new_server.name,
|
||||||
|
]
|
||||||
|
verifylist = [
|
||||||
|
('image', 'image1'),
|
||||||
|
('flavor', 'flavor1'),
|
||||||
|
('hypervisor_hostname', 'node1'),
|
||||||
|
('config_drive', False),
|
||||||
|
('server_name', self.new_server.name),
|
||||||
|
]
|
||||||
|
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
|
||||||
|
|
||||||
|
with mock.patch.object(api_versions,
|
||||||
|
'APIVersion',
|
||||||
|
return_value=2.74):
|
||||||
|
# In base command class ShowOne in cliff, abstract method
|
||||||
|
# take_action() returns a two-part tuple with a tuple of
|
||||||
|
# column names and a tuple of data to be shown.
|
||||||
|
columns, data = self.cmd.take_action(parsed_args)
|
||||||
|
|
||||||
|
# Set expected values
|
||||||
|
kwargs = dict(
|
||||||
|
meta=None,
|
||||||
|
files={},
|
||||||
|
reservation_id=None,
|
||||||
|
min_count=1,
|
||||||
|
max_count=1,
|
||||||
|
security_groups=[],
|
||||||
|
userdata=None,
|
||||||
|
key_name=None,
|
||||||
|
availability_zone=None,
|
||||||
|
block_device_mapping_v2=[],
|
||||||
|
nics='auto',
|
||||||
|
scheduler_hints={},
|
||||||
|
config_drive=None,
|
||||||
|
hypervisor_hostname='node1',
|
||||||
|
)
|
||||||
|
# ServerManager.create(name, image, flavor, **kwargs)
|
||||||
|
self.servers_mock.create.assert_called_with(
|
||||||
|
self.new_server.name,
|
||||||
|
self.image,
|
||||||
|
self.flavor,
|
||||||
|
**kwargs
|
||||||
|
)
|
||||||
|
|
||||||
|
self.assertEqual(self.columns, columns)
|
||||||
|
self.assertEqual(self.datalist(), data)
|
||||||
|
self.assertFalse(self.images_mock.called)
|
||||||
|
self.assertFalse(self.flavors_mock.called)
|
||||||
|
|
||||||
|
def test_server_create_with_hypervisor_hostname_pre_v274(self):
|
||||||
|
|
||||||
|
# Hypervisor_hostname is not supported for nova api version below 2.74
|
||||||
|
self.app.client_manager.compute.api_version = 2.73
|
||||||
|
|
||||||
|
arglist = [
|
||||||
|
'--image', 'image1',
|
||||||
|
'--flavor', 'flavor1',
|
||||||
|
'--hypervisor-hostname', 'node1',
|
||||||
|
self.new_server.name,
|
||||||
|
]
|
||||||
|
verifylist = [
|
||||||
|
('image', 'image1'),
|
||||||
|
('flavor', 'flavor1'),
|
||||||
|
('hypervisor_hostname', 'node1'),
|
||||||
|
('config_drive', False),
|
||||||
|
('server_name', self.new_server.name),
|
||||||
|
]
|
||||||
|
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
|
||||||
|
|
||||||
|
with mock.patch.object(api_versions,
|
||||||
|
'APIVersion',
|
||||||
|
return_value=2.74):
|
||||||
|
self.assertRaises(exceptions.CommandError, self.cmd.take_action,
|
||||||
|
parsed_args)
|
||||||
|
|
||||||
|
def test_server_create_with_host_and_hypervisor_hostname_v274(self):
|
||||||
|
|
||||||
|
# Explicit host and hypervisor_hostname is supported for nova api
|
||||||
|
# version 2.74 or above
|
||||||
|
self.app.client_manager.compute.api_version = 2.74
|
||||||
|
|
||||||
|
arglist = [
|
||||||
|
'--image', 'image1',
|
||||||
|
'--flavor', 'flavor1',
|
||||||
|
'--host', 'host1',
|
||||||
|
'--hypervisor-hostname', 'node1',
|
||||||
|
self.new_server.name,
|
||||||
|
]
|
||||||
|
verifylist = [
|
||||||
|
('image', 'image1'),
|
||||||
|
('flavor', 'flavor1'),
|
||||||
|
('host', 'host1'),
|
||||||
|
('hypervisor_hostname', 'node1'),
|
||||||
|
('config_drive', False),
|
||||||
|
('server_name', self.new_server.name),
|
||||||
|
]
|
||||||
|
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
|
||||||
|
|
||||||
|
with mock.patch.object(api_versions,
|
||||||
|
'APIVersion',
|
||||||
|
return_value=2.74):
|
||||||
|
# In base command class ShowOne in cliff, abstract method
|
||||||
|
# take_action() returns a two-part tuple with a tuple of
|
||||||
|
# column names and a tuple of data to be shown.
|
||||||
|
columns, data = self.cmd.take_action(parsed_args)
|
||||||
|
|
||||||
|
# Set expected values
|
||||||
|
kwargs = dict(
|
||||||
|
meta=None,
|
||||||
|
files={},
|
||||||
|
reservation_id=None,
|
||||||
|
min_count=1,
|
||||||
|
max_count=1,
|
||||||
|
security_groups=[],
|
||||||
|
userdata=None,
|
||||||
|
key_name=None,
|
||||||
|
availability_zone=None,
|
||||||
|
block_device_mapping_v2=[],
|
||||||
|
nics='auto',
|
||||||
|
scheduler_hints={},
|
||||||
|
config_drive=None,
|
||||||
|
host='host1',
|
||||||
|
hypervisor_hostname='node1',
|
||||||
|
)
|
||||||
|
# ServerManager.create(name, image, flavor, **kwargs)
|
||||||
|
self.servers_mock.create.assert_called_with(
|
||||||
|
self.new_server.name,
|
||||||
|
self.image,
|
||||||
|
self.flavor,
|
||||||
|
**kwargs
|
||||||
|
)
|
||||||
|
|
||||||
|
self.assertEqual(self.columns, columns)
|
||||||
|
self.assertEqual(self.datalist(), data)
|
||||||
|
self.assertFalse(self.images_mock.called)
|
||||||
|
self.assertFalse(self.flavors_mock.called)
|
||||||
|
|
||||||
|
|
||||||
class TestServerDelete(TestServer):
|
class TestServerDelete(TestServer):
|
||||||
|
|
||||||
|
@ -0,0 +1,6 @@
|
|||||||
|
---
|
||||||
|
features:
|
||||||
|
- |
|
||||||
|
Add ``--host`` and ``--hypervisor-hostname`` options to
|
||||||
|
``server create`` command.
|
||||||
|
[Blueprint `add-host-and-hypervisor-hostname-flag-to-create-server <https://blueprints.launchpad.net/nova/+spec/add-host-and-hypervisor-hostname-flag-to-create-server>`_]
|
@ -13,5 +13,5 @@ oslo.i18n>=3.15.3 # Apache-2.0
|
|||||||
oslo.utils>=3.33.0 # Apache-2.0
|
oslo.utils>=3.33.0 # Apache-2.0
|
||||||
python-glanceclient>=2.8.0 # Apache-2.0
|
python-glanceclient>=2.8.0 # Apache-2.0
|
||||||
python-keystoneclient>=3.17.0 # Apache-2.0
|
python-keystoneclient>=3.17.0 # Apache-2.0
|
||||||
python-novaclient>=14.1.0 # Apache-2.0
|
python-novaclient>=14.2.0 # Apache-2.0
|
||||||
python-cinderclient>=3.3.0 # Apache-2.0
|
python-cinderclient>=3.3.0 # Apache-2.0
|
||||||
|
Loading…
Reference in New Issue
Block a user