Drop bay and baymodel
Story: 2009104 Task: 42956 Signed-off-by: Diogo Guerra <diogo.filipe.tomas.guerra@cern.ch> Change-Id: I8f0076cae90a59c1d9ffca827eb0e80abe9b10d7
This commit is contained in:
parent
7c03bcb734
commit
7ad1c27ed7
@ -412,7 +412,7 @@ class SessionClientTest(utils.BaseTestCase):
|
||||
client = http.SessionClient(
|
||||
session=fake_session, endpoint_override='http://magnum')
|
||||
|
||||
client.json_request('GET', '/v1/bays')
|
||||
client.json_request('GET', '/v1/clusters')
|
||||
self.assertEqual(
|
||||
fake_session.request.call_args[1]['endpoint_override'],
|
||||
'http://magnum'
|
||||
@ -450,7 +450,7 @@ class SessionClientTest(utils.BaseTestCase):
|
||||
client = http.SessionClient(
|
||||
session=fake_session, endpoint_override='http://magnum')
|
||||
|
||||
resp, resp_body = client.raw_request('GET', '/v1/bays')
|
||||
resp, resp_body = client.raw_request('GET', '/v1/clusters')
|
||||
|
||||
self.assertEqual(
|
||||
fake_session.request.call_args[1]['headers']['Content-Type'],
|
||||
|
@ -1,354 +0,0 @@
|
||||
# Copyright 2015 NEC Corporation. All rights reserved.
|
||||
#
|
||||
# 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.
|
||||
|
||||
import io
|
||||
import re
|
||||
import sys
|
||||
from unittest import mock
|
||||
|
||||
import argparse
|
||||
import fixtures
|
||||
from keystoneauth1 import fixture
|
||||
from testtools import matchers
|
||||
|
||||
from magnumclient import exceptions
|
||||
import magnumclient.shell
|
||||
from magnumclient.tests import utils
|
||||
|
||||
FAKE_ENV = {'OS_USERNAME': 'username',
|
||||
'OS_PASSWORD': 'password',
|
||||
'OS_PROJECT_NAME': 'project_name',
|
||||
'OS_AUTH_URL': 'http://no.where/v2.0'}
|
||||
|
||||
FAKE_ENV2 = {'OS_USER_ID': 'user_id',
|
||||
'OS_PASSWORD': 'password',
|
||||
'OS_PROJECT_ID': 'project_id',
|
||||
'OS_AUTH_URL': 'http://no.where/v2.0'}
|
||||
|
||||
FAKE_ENV3 = {'OS_USERNAME': 'username',
|
||||
'OS_PASSWORD': 'password',
|
||||
'OS_PROJECT_ID': 'project_id',
|
||||
'OS_AUTH_URL': 'http://no.where/v2.0'}
|
||||
|
||||
FAKE_ENV4 = {'OS_USERNAME': 'username',
|
||||
'OS_PASSWORD': 'password',
|
||||
'OS_PROJECT_ID': 'project_id',
|
||||
'OS_USER_DOMAIN_NAME': 'Default',
|
||||
'OS_PROJECT_DOMAIN_NAME': 'Default',
|
||||
'OS_AUTH_URL': 'http://no.where/v3'}
|
||||
|
||||
|
||||
def _create_ver_list(versions):
|
||||
return {'versions': {'values': versions}}
|
||||
|
||||
|
||||
class ParserTest(utils.TestCase):
|
||||
|
||||
def setUp(self):
|
||||
super(ParserTest, self).setUp()
|
||||
self.parser = magnumclient.shell.MagnumClientArgumentParser()
|
||||
|
||||
def test_ambiguous_option(self):
|
||||
self.parser.add_argument('--tic')
|
||||
self.parser.add_argument('--tac')
|
||||
try:
|
||||
self.parser.parse_args(['--t'])
|
||||
except SystemExit as err:
|
||||
self.assertEqual(2, err.code)
|
||||
else:
|
||||
self.fail('SystemExit not raised')
|
||||
|
||||
|
||||
class ShellTest(utils.TestCase):
|
||||
AUTH_URL = utils.FAKE_ENV['OS_AUTH_URL']
|
||||
|
||||
_msg_no_tenant_project = ("You must provide a project name or project id"
|
||||
" via --os-project-name, --os-project-id,"
|
||||
" env[OS_PROJECT_NAME] or env[OS_PROJECT_ID]")
|
||||
|
||||
def setUp(self):
|
||||
super(ShellTest, self).setUp()
|
||||
self.nc_util = mock.patch(
|
||||
'magnumclient.common.cliutils.isunauthenticated').start()
|
||||
self.nc_util.return_value = False
|
||||
|
||||
def test_positive_non_zero_float(self):
|
||||
output = magnumclient.shell.positive_non_zero_float(None)
|
||||
self.assertIsNone(output)
|
||||
|
||||
output = magnumclient.shell.positive_non_zero_float(5)
|
||||
self.assertEqual(5, output)
|
||||
|
||||
output = magnumclient.shell.positive_non_zero_float(5.0)
|
||||
self.assertEqual(5.0, output)
|
||||
|
||||
self.assertRaises(argparse.ArgumentTypeError,
|
||||
magnumclient.shell.positive_non_zero_float,
|
||||
"Invalid")
|
||||
|
||||
self.assertRaises(argparse.ArgumentTypeError,
|
||||
magnumclient.shell.positive_non_zero_float, -1)
|
||||
|
||||
self.assertRaises(argparse.ArgumentTypeError,
|
||||
magnumclient.shell.positive_non_zero_float, 0)
|
||||
|
||||
def test_help_unknown_command(self):
|
||||
self.assertRaises(exceptions.CommandError, self.shell, 'help foofoo')
|
||||
|
||||
def test_help(self):
|
||||
required = [
|
||||
'.*?^usage: ',
|
||||
'.*?^See "magnum help COMMAND" for help on a specific command',
|
||||
]
|
||||
stdout, stderr = self.shell('help')
|
||||
for r in required:
|
||||
self.assertThat((stdout + stderr),
|
||||
matchers.MatchesRegex(r, re.DOTALL | re.MULTILINE))
|
||||
|
||||
def test_help_on_subcommand(self):
|
||||
required = [
|
||||
'.*?^usage: magnum bay-create',
|
||||
'.*?^Create a bay.'
|
||||
]
|
||||
# https://bugs.python.org/issue9694
|
||||
if sys.version_info[:2] >= (3, 10):
|
||||
required.append('.*?^Options:')
|
||||
else:
|
||||
required.append('.*?^Optional arguments:')
|
||||
stdout, stderr = self.shell('help bay-create')
|
||||
for r in required:
|
||||
self.assertThat((stdout + stderr),
|
||||
matchers.MatchesRegex(r, re.DOTALL | re.MULTILINE))
|
||||
|
||||
def test_help_no_options(self):
|
||||
required = [
|
||||
'.*?^usage: ',
|
||||
'.*?^See "magnum help COMMAND" for help on a specific command',
|
||||
]
|
||||
stdout, stderr = self.shell('')
|
||||
for r in required:
|
||||
self.assertThat((stdout + stderr),
|
||||
matchers.MatchesRegex(r, re.DOTALL | re.MULTILINE))
|
||||
|
||||
def test_bash_completion(self):
|
||||
stdout, stderr = self.shell('bash-completion')
|
||||
# just check we have some output
|
||||
required = [
|
||||
'.*help',
|
||||
'.*bay-show',
|
||||
'.*--bay']
|
||||
for r in required:
|
||||
self.assertThat((stdout + stderr),
|
||||
matchers.MatchesRegex(r, re.DOTALL | re.MULTILINE))
|
||||
|
||||
def test_no_username(self):
|
||||
required = ('You must provide a username via'
|
||||
' either --os-username or via env[OS_USERNAME]')
|
||||
self.make_env(exclude='OS_USERNAME')
|
||||
try:
|
||||
self.shell('bay-list')
|
||||
except exceptions.CommandError as message:
|
||||
self.assertEqual(required, message.args[0])
|
||||
else:
|
||||
self.fail('CommandError not raised')
|
||||
|
||||
def test_no_user_id(self):
|
||||
required = ('You must provide a username via'
|
||||
' either --os-username or via env[OS_USERNAME]')
|
||||
self.make_env(exclude='OS_USER_ID', fake_env=FAKE_ENV2)
|
||||
try:
|
||||
self.shell('bay-list')
|
||||
except exceptions.CommandError as message:
|
||||
self.assertEqual(required, message.args[0])
|
||||
else:
|
||||
self.fail('CommandError not raised')
|
||||
|
||||
def test_no_project_name(self):
|
||||
required = self._msg_no_tenant_project
|
||||
self.make_env(exclude='OS_PROJECT_NAME')
|
||||
try:
|
||||
self.shell('bay-list')
|
||||
except exceptions.CommandError as message:
|
||||
self.assertEqual(required, message.args[0])
|
||||
else:
|
||||
self.fail('CommandError not raised')
|
||||
|
||||
def test_no_project_id(self):
|
||||
required = self._msg_no_tenant_project
|
||||
self.make_env(exclude='OS_PROJECT_ID', fake_env=FAKE_ENV3)
|
||||
try:
|
||||
self.shell('bay-list')
|
||||
except exceptions.CommandError as message:
|
||||
self.assertEqual(required, message.args[0])
|
||||
else:
|
||||
self.fail('CommandError not raised')
|
||||
|
||||
def test_no_password(self):
|
||||
required = ('You must provide a password via either --os-password, '
|
||||
'env[OS_PASSWORD], or prompted response')
|
||||
self.make_env(exclude='OS_PASSWORD', fake_env=FAKE_ENV3)
|
||||
try:
|
||||
self.shell('bay-list')
|
||||
except exceptions.CommandError as message:
|
||||
self.assertEqual(required, message.args[0])
|
||||
else:
|
||||
self.fail('CommandError not raised')
|
||||
|
||||
def test_no_auth_url(self):
|
||||
required = ("You must provide an auth url via either "
|
||||
"--os-auth-url or via env[OS_AUTH_URL]")
|
||||
self.make_env(exclude='OS_AUTH_URL')
|
||||
try:
|
||||
self.shell('bay-list')
|
||||
except exceptions.CommandError as message:
|
||||
self.assertEqual(required, message.args[0])
|
||||
else:
|
||||
self.fail('CommandError not raised')
|
||||
|
||||
# FIXME(madhuri) Remove this harcoded v1 Client class.
|
||||
# In future, when a new version of API will
|
||||
# introduce, this needs to be dynamic then.
|
||||
@mock.patch('magnumclient.v1.client.Client')
|
||||
def test_service_type(self, mock_client):
|
||||
self.make_env()
|
||||
self.shell('bay-list')
|
||||
_, client_kwargs = mock_client.call_args_list[0]
|
||||
self.assertEqual('container-infra', client_kwargs['service_type'])
|
||||
|
||||
@mock.patch('magnumclient.v1.bays_shell.do_bay_list')
|
||||
@mock.patch('magnumclient.v1.client.ksa_session')
|
||||
def test_insecure(self, mock_session, mock_bay_list):
|
||||
self.make_env()
|
||||
self.shell('--insecure bay-list')
|
||||
_, session_kwargs = mock_session.Session.call_args_list[0]
|
||||
self.assertEqual(False, session_kwargs['verify'])
|
||||
|
||||
@mock.patch('sys.argv', ['magnum'])
|
||||
@mock.patch('sys.stdout', io.StringIO())
|
||||
@mock.patch('sys.stderr', io.StringIO())
|
||||
def test_main_noargs(self):
|
||||
# Ensure that main works with no command-line arguments
|
||||
try:
|
||||
magnumclient.shell.main()
|
||||
except SystemExit:
|
||||
self.fail('Unexpected SystemExit')
|
||||
|
||||
# We expect the normal usage as a result
|
||||
self.assertIn('Command-line interface to the OpenStack Magnum API',
|
||||
sys.stdout.getvalue())
|
||||
|
||||
def _expected_client_kwargs(self):
|
||||
return {
|
||||
'password': 'password', 'auth_token': None,
|
||||
'auth_url': self.AUTH_URL, 'profile': None,
|
||||
'cloud': None, 'interface': 'public',
|
||||
'insecure': False, 'magnum_url': None,
|
||||
'project_id': None, 'project_name': 'project_name',
|
||||
'project_domain_id': None, 'project_domain_name': None,
|
||||
'region_name': None, 'service_type': 'container-infra',
|
||||
'user_id': None, 'username': 'username',
|
||||
'user_domain_id': None, 'user_domain_name': None,
|
||||
'api_version': 'latest'
|
||||
}
|
||||
|
||||
@mock.patch('magnumclient.v1.client.Client')
|
||||
def _test_main_region(self, command, expected_region_name, mock_client):
|
||||
self.shell(command)
|
||||
expected_args = self._expected_client_kwargs()
|
||||
expected_args['region_name'] = expected_region_name
|
||||
mock_client.assert_called_once_with(**expected_args)
|
||||
|
||||
def test_main_option_region(self):
|
||||
self.make_env()
|
||||
self._test_main_region('--os-region-name=myregion bay-list',
|
||||
'myregion')
|
||||
|
||||
def test_main_env_region(self):
|
||||
fake_env = dict(utils.FAKE_ENV, OS_REGION_NAME='myregion')
|
||||
self.make_env(fake_env=fake_env)
|
||||
self._test_main_region('bay-list', 'myregion')
|
||||
|
||||
def test_main_no_region(self):
|
||||
self.make_env()
|
||||
self._test_main_region('bay-list', None)
|
||||
|
||||
@mock.patch('magnumclient.v1.client.Client')
|
||||
def test_main_endpoint_public(self, mock_client):
|
||||
self.make_env()
|
||||
self.shell('--endpoint-type publicURL bay-list')
|
||||
expected_args = self._expected_client_kwargs()
|
||||
expected_args['interface'] = 'public'
|
||||
mock_client.assert_called_once_with(**expected_args)
|
||||
|
||||
@mock.patch('magnumclient.v1.client.Client')
|
||||
def test_main_endpoint_internal(self, mock_client):
|
||||
self.make_env()
|
||||
self.shell('--endpoint-type internalURL bay-list')
|
||||
expected_args = self._expected_client_kwargs()
|
||||
expected_args['interface'] = 'internal'
|
||||
mock_client.assert_called_once_with(**expected_args)
|
||||
|
||||
@mock.patch('magnumclient.v1.client.Client')
|
||||
def test_main_os_cloud(self, mock_client):
|
||||
expected_cloud = 'default'
|
||||
self.shell('--os-cloud %s bay-list' % expected_cloud)
|
||||
expected_args = self._expected_client_kwargs()
|
||||
expected_args['cloud'] = expected_cloud
|
||||
expected_args['username'] = None
|
||||
expected_args['password'] = None
|
||||
expected_args['project_name'] = None
|
||||
expected_args['auth_url'] = None
|
||||
mock_client.assert_called_once_with(**expected_args)
|
||||
|
||||
@mock.patch('magnumclient.v1.client.Client')
|
||||
def test_main_env_os_cloud(self, mock_client):
|
||||
expected_cloud = 'default'
|
||||
self.make_env(fake_env={'OS_CLOUD': expected_cloud})
|
||||
self.shell('bay-list')
|
||||
expected_args = self._expected_client_kwargs()
|
||||
expected_args['cloud'] = expected_cloud
|
||||
expected_args['username'] = None
|
||||
expected_args['password'] = None
|
||||
expected_args['project_name'] = None
|
||||
expected_args['auth_url'] = None
|
||||
mock_client.assert_called_once_with(**expected_args)
|
||||
|
||||
|
||||
class ShellTestKeystoneV3(ShellTest):
|
||||
AUTH_URL = 'http://no.where/v3'
|
||||
|
||||
def make_env(self, exclude=None, fake_env=FAKE_ENV):
|
||||
if 'OS_AUTH_URL' in fake_env:
|
||||
fake_env.update({'OS_AUTH_URL': self.AUTH_URL})
|
||||
env = dict((k, v) for k, v in fake_env.items() if k != exclude)
|
||||
self.useFixture(fixtures.MonkeyPatch('os.environ', env))
|
||||
|
||||
def register_keystone_discovery_fixture(self, mreq):
|
||||
v3_url = "http://no.where/v3"
|
||||
v3_version = fixture.V3Discovery(v3_url)
|
||||
mreq.register_uri(
|
||||
'GET', v3_url, json=_create_ver_list([v3_version]),
|
||||
status_code=200)
|
||||
|
||||
@mock.patch('magnumclient.v1.client.Client')
|
||||
def test_main_endpoint_public(self, mock_client):
|
||||
self.make_env(fake_env=FAKE_ENV4)
|
||||
self.shell('--endpoint-type publicURL bay-list')
|
||||
expected_args = self._expected_client_kwargs()
|
||||
expected_args['interface'] = 'public'
|
||||
expected_args['project_id'] = 'project_id'
|
||||
expected_args['project_name'] = None
|
||||
expected_args['project_domain_name'] = 'Default'
|
||||
expected_args['user_domain_name'] = 'Default'
|
||||
mock_client.assert_called_once_with(**expected_args)
|
@ -75,10 +75,6 @@ class TestCommandLineArgument(utils.TestCase):
|
||||
r".*?^Try 'magnum help ",
|
||||
]
|
||||
|
||||
_bay_status_error = [
|
||||
r'.*?^Bay status for',
|
||||
]
|
||||
|
||||
def setUp(self):
|
||||
super(TestCommandLineArgument, self).setUp()
|
||||
self.make_env(fake_env=FAKE_ENV)
|
||||
|
@ -1,362 +0,0 @@
|
||||
# Copyright 2015 IBM Corp.
|
||||
#
|
||||
# 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.
|
||||
|
||||
import copy
|
||||
|
||||
import testtools
|
||||
from testtools import matchers
|
||||
|
||||
from magnumclient import exceptions
|
||||
from magnumclient.tests import utils
|
||||
from magnumclient.v1 import baymodels
|
||||
|
||||
BAYMODEL1 = {'id': 123,
|
||||
'uuid': '66666666-7777-8888-9999-000000000001',
|
||||
'name': 'baymodel1',
|
||||
'image_id': 'baymodel1-image',
|
||||
'master_flavor_id': 'm1.tiny',
|
||||
'flavor_id': 'm1.small',
|
||||
'keypair_id': 'keypair1',
|
||||
'external_network_id': 'd1f02cfb-d27f-4068-9332-84d907cb0e21',
|
||||
'fixed_network': 'private',
|
||||
'fixed_subnet': 'private-subnet',
|
||||
'network_driver': 'libnetwork',
|
||||
'volume_driver': 'rexray',
|
||||
'dns_nameserver': '8.8.1.1',
|
||||
'docker_volume_size': '71',
|
||||
'docker_storage_driver': 'devicemapper',
|
||||
'coe': 'swarm',
|
||||
'http_proxy': 'http_proxy',
|
||||
'https_proxy': 'https_proxy',
|
||||
'no_proxy': 'no_proxy',
|
||||
'labels': 'key1=val1,key11=val11',
|
||||
'tls_disabled': False,
|
||||
'public': False,
|
||||
'registry_enabled': False,
|
||||
'master_lb_enabled': True,
|
||||
'floating_ip_enabled': True,
|
||||
}
|
||||
|
||||
BAYMODEL2 = {'id': 124,
|
||||
'uuid': '66666666-7777-8888-9999-000000000002',
|
||||
'name': 'baymodel2',
|
||||
'image_id': 'baymodel2-image',
|
||||
'flavor_id': 'm2.small',
|
||||
'master_flavor_id': 'm2.tiny',
|
||||
'keypair_id': 'keypair2',
|
||||
'external_network_id': 'd1f02cfb-d27f-4068-9332-84d907cb0e22',
|
||||
'fixed_network': 'private2',
|
||||
'network_driver': 'flannel',
|
||||
'volume_driver': 'cinder',
|
||||
'dns_nameserver': '8.8.1.2',
|
||||
'docker_volume_size': '50',
|
||||
'docker_storage_driver': 'overlay',
|
||||
'coe': 'kubernetes',
|
||||
'labels': 'key2=val2,key22=val22',
|
||||
'tls_disabled': True,
|
||||
'public': True,
|
||||
'registry_enabled': True}
|
||||
|
||||
CREATE_BAYMODEL = copy.deepcopy(BAYMODEL1)
|
||||
del CREATE_BAYMODEL['id']
|
||||
del CREATE_BAYMODEL['uuid']
|
||||
|
||||
UPDATED_BAYMODEL = copy.deepcopy(BAYMODEL1)
|
||||
NEW_NAME = 'newbay'
|
||||
UPDATED_BAYMODEL['name'] = NEW_NAME
|
||||
|
||||
fake_responses = {
|
||||
'/v1/baymodels':
|
||||
{
|
||||
'GET': (
|
||||
{},
|
||||
{'baymodels': [BAYMODEL1, BAYMODEL2]},
|
||||
),
|
||||
'POST': (
|
||||
{},
|
||||
CREATE_BAYMODEL,
|
||||
),
|
||||
},
|
||||
'/v1/baymodels/%s' % BAYMODEL1['id']:
|
||||
{
|
||||
'GET': (
|
||||
{},
|
||||
BAYMODEL1
|
||||
),
|
||||
'DELETE': (
|
||||
{},
|
||||
None,
|
||||
),
|
||||
'PATCH': (
|
||||
{},
|
||||
UPDATED_BAYMODEL,
|
||||
),
|
||||
},
|
||||
'/v1/baymodels/%s' % BAYMODEL1['name']:
|
||||
{
|
||||
'GET': (
|
||||
{},
|
||||
BAYMODEL1
|
||||
),
|
||||
'DELETE': (
|
||||
{},
|
||||
None,
|
||||
),
|
||||
'PATCH': (
|
||||
{},
|
||||
UPDATED_BAYMODEL,
|
||||
),
|
||||
},
|
||||
'/v1/baymodels/detail':
|
||||
{
|
||||
'GET': (
|
||||
{},
|
||||
{'baymodels': [BAYMODEL1, BAYMODEL2]},
|
||||
),
|
||||
},
|
||||
'/v1/baymodels/?limit=2':
|
||||
{
|
||||
'GET': (
|
||||
{},
|
||||
{'baymodels': [BAYMODEL1, BAYMODEL2]},
|
||||
),
|
||||
},
|
||||
'/v1/baymodels/?marker=%s' % BAYMODEL2['uuid']:
|
||||
{
|
||||
'GET': (
|
||||
{},
|
||||
{'baymodels': [BAYMODEL1, BAYMODEL2]},
|
||||
),
|
||||
},
|
||||
'/v1/baymodels/?limit=2&marker=%s' % BAYMODEL2['uuid']:
|
||||
{
|
||||
'GET': (
|
||||
{},
|
||||
{'baymodels': [BAYMODEL1, BAYMODEL2]},
|
||||
),
|
||||
},
|
||||
'/v1/baymodels/?sort_dir=asc':
|
||||
{
|
||||
'GET': (
|
||||
{},
|
||||
{'baymodels': [BAYMODEL1, BAYMODEL2]},
|
||||
),
|
||||
},
|
||||
'/v1/baymodels/?sort_key=uuid':
|
||||
{
|
||||
'GET': (
|
||||
{},
|
||||
{'baymodels': [BAYMODEL1, BAYMODEL2]},
|
||||
),
|
||||
},
|
||||
'/v1/baymodels/?sort_key=uuid&sort_dir=desc':
|
||||
{
|
||||
'GET': (
|
||||
{},
|
||||
{'baymodels': [BAYMODEL2, BAYMODEL1]},
|
||||
),
|
||||
},
|
||||
}
|
||||
|
||||
|
||||
class BayModelManagerTest(testtools.TestCase):
|
||||
|
||||
def setUp(self):
|
||||
super(BayModelManagerTest, self).setUp()
|
||||
self.api = utils.FakeAPI(fake_responses)
|
||||
self.mgr = baymodels.BayModelManager(self.api)
|
||||
|
||||
def test_baymodel_list(self):
|
||||
baymodels = self.mgr.list()
|
||||
expect = [
|
||||
('GET', '/v1/baymodels', {}, None),
|
||||
]
|
||||
self.assertEqual(expect, self.api.calls)
|
||||
self.assertThat(baymodels, matchers.HasLength(2))
|
||||
|
||||
def _test_baymodel_list_with_filters(
|
||||
self, limit=None, marker=None,
|
||||
sort_key=None, sort_dir=None,
|
||||
detail=False, expect=[]):
|
||||
baymodels_filter = self.mgr.list(limit=limit, marker=marker,
|
||||
sort_key=sort_key,
|
||||
sort_dir=sort_dir,
|
||||
detail=detail)
|
||||
self.assertEqual(expect, self.api.calls)
|
||||
self.assertThat(baymodels_filter, matchers.HasLength(2))
|
||||
|
||||
def test_baymodel_list_with_detail(self):
|
||||
expect = [
|
||||
('GET', '/v1/baymodels/detail', {}, None),
|
||||
]
|
||||
self._test_baymodel_list_with_filters(
|
||||
detail=True,
|
||||
expect=expect)
|
||||
|
||||
def test_baymodel_list_with_limit(self):
|
||||
expect = [
|
||||
('GET', '/v1/baymodels/?limit=2', {}, None),
|
||||
]
|
||||
self._test_baymodel_list_with_filters(
|
||||
limit=2,
|
||||
expect=expect)
|
||||
|
||||
def test_baymodel_list_with_marker(self):
|
||||
expect = [
|
||||
('GET', '/v1/baymodels/?marker=%s' % BAYMODEL2['uuid'], {}, None),
|
||||
]
|
||||
self._test_baymodel_list_with_filters(
|
||||
marker=BAYMODEL2['uuid'],
|
||||
expect=expect)
|
||||
|
||||
def test_baymodel_list_with_marker_limit(self):
|
||||
expect = [
|
||||
('GET', '/v1/baymodels/?limit=2&marker=%s' % BAYMODEL2['uuid'],
|
||||
{}, None),
|
||||
]
|
||||
self._test_baymodel_list_with_filters(
|
||||
limit=2, marker=BAYMODEL2['uuid'],
|
||||
expect=expect)
|
||||
|
||||
def test_baymodel_list_with_sort_dir(self):
|
||||
expect = [
|
||||
('GET', '/v1/baymodels/?sort_dir=asc', {}, None),
|
||||
]
|
||||
self._test_baymodel_list_with_filters(
|
||||
sort_dir='asc',
|
||||
expect=expect)
|
||||
|
||||
def test_baymodel_list_with_sort_key(self):
|
||||
expect = [
|
||||
('GET', '/v1/baymodels/?sort_key=uuid', {}, None),
|
||||
]
|
||||
self._test_baymodel_list_with_filters(
|
||||
sort_key='uuid',
|
||||
expect=expect)
|
||||
|
||||
def test_baymodel_list_with_sort_key_dir(self):
|
||||
expect = [
|
||||
('GET', '/v1/baymodels/?sort_key=uuid&sort_dir=desc', {}, None),
|
||||
]
|
||||
self._test_baymodel_list_with_filters(
|
||||
sort_key='uuid', sort_dir='desc',
|
||||
expect=expect)
|
||||
|
||||
def test_baymodel_show_by_id(self):
|
||||
baymodel = self.mgr.get(BAYMODEL1['id'])
|
||||
expect = [
|
||||
('GET', '/v1/baymodels/%s' % BAYMODEL1['id'], {}, None)
|
||||
]
|
||||
self.assertEqual(expect, self.api.calls)
|
||||
self.assertEqual(BAYMODEL1['name'], baymodel.name)
|
||||
self.assertEqual(BAYMODEL1['image_id'], baymodel.image_id)
|
||||
self.assertEqual(BAYMODEL1['docker_volume_size'],
|
||||
baymodel.docker_volume_size)
|
||||
self.assertEqual(BAYMODEL1['docker_storage_driver'],
|
||||
baymodel.docker_storage_driver)
|
||||
self.assertEqual(BAYMODEL1['fixed_network'], baymodel.fixed_network)
|
||||
self.assertEqual(BAYMODEL1['fixed_subnet'], baymodel.fixed_subnet)
|
||||
self.assertEqual(BAYMODEL1['coe'], baymodel.coe)
|
||||
self.assertEqual(BAYMODEL1['http_proxy'], baymodel.http_proxy)
|
||||
self.assertEqual(BAYMODEL1['https_proxy'], baymodel.https_proxy)
|
||||
self.assertEqual(BAYMODEL1['no_proxy'], baymodel.no_proxy)
|
||||
self.assertEqual(BAYMODEL1['network_driver'], baymodel.network_driver)
|
||||
self.assertEqual(BAYMODEL1['volume_driver'], baymodel.volume_driver)
|
||||
self.assertEqual(BAYMODEL1['labels'], baymodel.labels)
|
||||
self.assertEqual(BAYMODEL1['tls_disabled'], baymodel.tls_disabled)
|
||||
self.assertEqual(BAYMODEL1['public'], baymodel.public)
|
||||
self.assertEqual(BAYMODEL1['registry_enabled'],
|
||||
baymodel.registry_enabled)
|
||||
self.assertEqual(BAYMODEL1['master_lb_enabled'],
|
||||
baymodel.master_lb_enabled)
|
||||
self.assertEqual(BAYMODEL1['floating_ip_enabled'],
|
||||
baymodel.floating_ip_enabled)
|
||||
|
||||
def test_baymodel_show_by_name(self):
|
||||
baymodel = self.mgr.get(BAYMODEL1['name'])
|
||||
expect = [
|
||||
('GET', '/v1/baymodels/%s' % BAYMODEL1['name'], {}, None)
|
||||
]
|
||||
self.assertEqual(expect, self.api.calls)
|
||||
self.assertEqual(BAYMODEL1['name'], baymodel.name)
|
||||
self.assertEqual(BAYMODEL1['image_id'], baymodel.image_id)
|
||||
self.assertEqual(BAYMODEL1['docker_volume_size'],
|
||||
baymodel.docker_volume_size)
|
||||
self.assertEqual(BAYMODEL1['docker_storage_driver'],
|
||||
baymodel.docker_storage_driver)
|
||||
self.assertEqual(BAYMODEL1['fixed_network'], baymodel.fixed_network)
|
||||
self.assertEqual(BAYMODEL1['fixed_subnet'], baymodel.fixed_subnet)
|
||||
self.assertEqual(BAYMODEL1['coe'], baymodel.coe)
|
||||
self.assertEqual(BAYMODEL1['http_proxy'], baymodel.http_proxy)
|
||||
self.assertEqual(BAYMODEL1['https_proxy'], baymodel.https_proxy)
|
||||
self.assertEqual(BAYMODEL1['no_proxy'], baymodel.no_proxy)
|
||||
self.assertEqual(BAYMODEL1['network_driver'], baymodel.network_driver)
|
||||
self.assertEqual(BAYMODEL1['volume_driver'], baymodel.volume_driver)
|
||||
self.assertEqual(BAYMODEL1['labels'], baymodel.labels)
|
||||
self.assertEqual(BAYMODEL1['tls_disabled'], baymodel.tls_disabled)
|
||||
self.assertEqual(BAYMODEL1['public'], baymodel.public)
|
||||
self.assertEqual(BAYMODEL1['registry_enabled'],
|
||||
baymodel.registry_enabled)
|
||||
self.assertEqual(BAYMODEL1['master_lb_enabled'],
|
||||
baymodel.master_lb_enabled)
|
||||
self.assertEqual(BAYMODEL1['floating_ip_enabled'],
|
||||
baymodel.floating_ip_enabled)
|
||||
|
||||
def test_baymodel_create(self):
|
||||
baymodel = self.mgr.create(**CREATE_BAYMODEL)
|
||||
expect = [
|
||||
('POST', '/v1/baymodels', {}, CREATE_BAYMODEL),
|
||||
]
|
||||
self.assertEqual(expect, self.api.calls)
|
||||
self.assertTrue(baymodel)
|
||||
self.assertEqual(BAYMODEL1['docker_volume_size'],
|
||||
baymodel.docker_volume_size)
|
||||
self.assertEqual(BAYMODEL1['docker_storage_driver'],
|
||||
baymodel.docker_storage_driver)
|
||||
|
||||
def test_baymodel_create_fail(self):
|
||||
CREATE_BAYMODEL_FAIL = copy.deepcopy(CREATE_BAYMODEL)
|
||||
CREATE_BAYMODEL_FAIL["wrong_key"] = "wrong"
|
||||
self.assertRaisesRegex(exceptions.InvalidAttribute,
|
||||
("Key must be in %s" %
|
||||
','.join(baymodels.CREATION_ATTRIBUTES)),
|
||||
self.mgr.create, **CREATE_BAYMODEL_FAIL)
|
||||
self.assertEqual([], self.api.calls)
|
||||
|
||||
def test_baymodel_delete_by_id(self):
|
||||
baymodel = self.mgr.delete(BAYMODEL1['id'])
|
||||
expect = [
|
||||
('DELETE', '/v1/baymodels/%s' % BAYMODEL1['id'], {}, None),
|
||||
]
|
||||
self.assertEqual(expect, self.api.calls)
|
||||
self.assertIsNone(baymodel)
|
||||
|
||||
def test_baymodel_delete_by_name(self):
|
||||
baymodel = self.mgr.delete(BAYMODEL1['name'])
|
||||
expect = [
|
||||
('DELETE', '/v1/baymodels/%s' % BAYMODEL1['name'], {}, None),
|
||||
]
|
||||
self.assertEqual(expect, self.api.calls)
|
||||
self.assertIsNone(baymodel)
|
||||
|
||||
def test_baymodel_update(self):
|
||||
patch = {'op': 'replace',
|
||||
'value': NEW_NAME,
|
||||
'path': '/name'}
|
||||
baymodel = self.mgr.update(id=BAYMODEL1['id'], patch=patch)
|
||||
expect = [
|
||||
('PATCH', '/v1/baymodels/%s' % BAYMODEL1['id'], {}, patch),
|
||||
]
|
||||
self.assertEqual(expect, self.api.calls)
|
||||
self.assertEqual(NEW_NAME, baymodel.name)
|
@ -1,614 +0,0 @@
|
||||
# Copyright 2015 NEC Corporation. All rights reserved.
|
||||
#
|
||||
# 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.
|
||||
|
||||
from unittest import mock
|
||||
|
||||
from magnumclient.common.apiclient import exceptions
|
||||
from magnumclient.tests.v1 import shell_test_base
|
||||
from magnumclient.v1.baymodels import BayModel
|
||||
|
||||
|
||||
class FakeBayModel(BayModel):
|
||||
def __init__(self, manager=None, info={}, **kwargs):
|
||||
BayModel.__init__(self, manager=manager, info=info)
|
||||
self.apiserver_port = kwargs.get('apiserver_port', None)
|
||||
self.uuid = kwargs.get('uuid', 'x')
|
||||
self.links = kwargs.get('links', [])
|
||||
self.server_type = kwargs.get('server_type', 'vm')
|
||||
self.image_id = kwargs.get('image_id', 'x')
|
||||
self.tls_disabled = kwargs.get('tls_disabled', False)
|
||||
self.registry_enabled = kwargs.get('registry_enabled', False)
|
||||
self.coe = kwargs.get('coe', 'x')
|
||||
self.public = kwargs.get('public', False)
|
||||
self.name = kwargs.get('name', 'x')
|
||||
|
||||
|
||||
class ShellTest(shell_test_base.TestCommandLineArgument):
|
||||
|
||||
def _get_expected_args_list(self, limit=None, sort_dir=None,
|
||||
sort_key=None, detail=False):
|
||||
expected_args = {}
|
||||
expected_args['limit'] = limit
|
||||
expected_args['sort_dir'] = sort_dir
|
||||
expected_args['sort_key'] = sort_key
|
||||
expected_args['detail'] = detail
|
||||
|
||||
return expected_args
|
||||
|
||||
def _get_expected_args(self, image_id, external_network_id, coe,
|
||||
master_flavor_id=None, name=None,
|
||||
keypair_id=None, fixed_network=None,
|
||||
fixed_subnet=None, network_driver=None,
|
||||
volume_driver=None, dns_nameserver='8.8.8.8',
|
||||
flavor_id='m1.medium',
|
||||
docker_storage_driver='devicemapper',
|
||||
docker_volume_size=None, http_proxy=None,
|
||||
https_proxy=None, no_proxy=None, labels={},
|
||||
tls_disabled=False, public=False,
|
||||
master_lb_enabled=False, server_type='vm',
|
||||
registry_enabled=False, floating_ip_enabled=None):
|
||||
|
||||
expected_args = {}
|
||||
expected_args['image_id'] = image_id
|
||||
expected_args['external_network_id'] = external_network_id
|
||||
expected_args['coe'] = coe
|
||||
expected_args['master_flavor_id'] = master_flavor_id
|
||||
expected_args['name'] = name
|
||||
expected_args['keypair_id'] = keypair_id
|
||||
expected_args['fixed_network'] = fixed_network
|
||||
expected_args['fixed_subnet'] = fixed_subnet
|
||||
expected_args['network_driver'] = network_driver
|
||||
expected_args['volume_driver'] = volume_driver
|
||||
expected_args['dns_nameserver'] = dns_nameserver
|
||||
expected_args['flavor_id'] = flavor_id
|
||||
expected_args['docker_volume_size'] = docker_volume_size
|
||||
expected_args['docker_storage_driver'] = docker_storage_driver
|
||||
expected_args['http_proxy'] = http_proxy
|
||||
expected_args['https_proxy'] = https_proxy
|
||||
expected_args['no_proxy'] = no_proxy
|
||||
expected_args['labels'] = labels
|
||||
expected_args['tls_disabled'] = tls_disabled
|
||||
expected_args['public'] = public
|
||||
expected_args['master_lb_enabled'] = master_lb_enabled
|
||||
expected_args['server_type'] = server_type
|
||||
expected_args['registry_enabled'] = registry_enabled
|
||||
|
||||
return expected_args
|
||||
|
||||
@mock.patch('magnumclient.v1.baymodels.BayModelManager.create')
|
||||
def test_baymodel_create_success(self, mock_create):
|
||||
self._test_arg_success('baymodel-create '
|
||||
'--name test '
|
||||
'--image-id test_image '
|
||||
'--keypair-id test_keypair '
|
||||
'--external-network-id test_net '
|
||||
'--coe swarm '
|
||||
'--dns-nameserver test_dns '
|
||||
'--flavor-id test_flavor '
|
||||
'--fixed-network private '
|
||||
'--fixed-subnet private-subnet '
|
||||
'--volume-driver test_volume '
|
||||
'--network-driver test_driver '
|
||||
'--labels key=val '
|
||||
'--master-flavor-id test_flavor '
|
||||
'--docker-volume-size 10 '
|
||||
'--docker-storage-driver devicemapper '
|
||||
'--public '
|
||||
'--server-type vm '
|
||||
'--master-lb-enabled '
|
||||
'--floating-ip-enabled ')
|
||||
expected_args = \
|
||||
self._get_expected_args(name='test', image_id='test_image',
|
||||
keypair_id='test_keypair', coe='swarm',
|
||||
external_network_id='test_net',
|
||||
dns_nameserver='test_dns', public=True,
|
||||
flavor_id='test_flavor',
|
||||
master_flavor_id='test_flavor',
|
||||
fixed_network='private',
|
||||
fixed_subnet='private-subnet',
|
||||
server_type='vm',
|
||||
network_driver='test_driver',
|
||||
volume_driver='test_volume',
|
||||
docker_storage_driver='devicemapper',
|
||||
docker_volume_size=10,
|
||||
master_lb_enabled=True,
|
||||
labels={'key': 'val'})
|
||||
expected_args['floating_ip_enabled'] = True
|
||||
mock_create.assert_called_with(**expected_args)
|
||||
|
||||
self._test_arg_success('baymodel-create '
|
||||
'--keypair-id test_keypair '
|
||||
'--external-network-id test_net '
|
||||
'--image-id test_image '
|
||||
'--coe kubernetes '
|
||||
'--name test '
|
||||
'--server-type vm')
|
||||
expected_args = \
|
||||
self._get_expected_args(name='test', image_id='test_image',
|
||||
keypair_id='test_keypair',
|
||||
coe='kubernetes',
|
||||
external_network_id='test_net',
|
||||
server_type='vm')
|
||||
mock_create.assert_called_with(**expected_args)
|
||||
|
||||
self._test_arg_success('baymodel-create '
|
||||
'--keypair-id test_keypair '
|
||||
'--external-network-id test_net '
|
||||
'--image-id test_image '
|
||||
'--coe kubernetes '
|
||||
'--name test '
|
||||
'--server-type vm '
|
||||
'--floating-ip-disabled ')
|
||||
expected_args = \
|
||||
self._get_expected_args(name='test', image_id='test_image',
|
||||
keypair_id='test_keypair',
|
||||
coe='kubernetes',
|
||||
external_network_id='test_net',
|
||||
server_type='vm',
|
||||
floating_ip_enabled=False)
|
||||
mock_create.assert_called_with(**expected_args)
|
||||
|
||||
@mock.patch('magnumclient.v1.baymodels.BayModelManager.create')
|
||||
def test_baymodel_create_success_no_servertype(self, mock_create):
|
||||
self._test_arg_success('baymodel-create '
|
||||
'--name test '
|
||||
'--image-id test_image '
|
||||
'--keypair-id test_keypair '
|
||||
'--external-network-id test_net '
|
||||
'--coe swarm '
|
||||
'--dns-nameserver test_dns '
|
||||
'--flavor-id test_flavor '
|
||||
'--fixed-network public '
|
||||
'--network-driver test_driver '
|
||||
'--labels key=val '
|
||||
'--master-flavor-id test_flavor '
|
||||
'--docker-volume-size 10 '
|
||||
'--docker-storage-driver devicemapper '
|
||||
'--public ')
|
||||
expected_args = \
|
||||
self._get_expected_args(name='test', image_id='test_image',
|
||||
keypair_id='test_keypair', coe='swarm',
|
||||
external_network_id='test_net',
|
||||
dns_nameserver='test_dns', public=True,
|
||||
flavor_id='test_flavor',
|
||||
master_flavor_id='test_flavor',
|
||||
fixed_network='public',
|
||||
network_driver='test_driver',
|
||||
docker_storage_driver='devicemapper',
|
||||
docker_volume_size=10,
|
||||
labels={'key': 'val'})
|
||||
mock_create.assert_called_with(**expected_args)
|
||||
|
||||
self._test_arg_success('baymodel-create '
|
||||
'--keypair-id test_keypair '
|
||||
'--external-network-id test_net '
|
||||
'--image-id test_image '
|
||||
'--coe kubernetes '
|
||||
'--name test ')
|
||||
|
||||
expected_args = \
|
||||
self._get_expected_args(name='test', image_id='test_image',
|
||||
keypair_id='test_keypair',
|
||||
coe='kubernetes',
|
||||
external_network_id='test_net')
|
||||
mock_create.assert_called_with(**expected_args)
|
||||
|
||||
@mock.patch('magnumclient.v1.baymodels.BayModelManager.create')
|
||||
def test_baymodel_create_success_with_registry_enabled(
|
||||
self, mock_create):
|
||||
self._test_arg_success('baymodel-create '
|
||||
'--name test '
|
||||
'--network-driver test_driver '
|
||||
'--keypair-id test_keypair '
|
||||
'--external-network-id test_net '
|
||||
'--image-id test_image '
|
||||
'--coe swarm '
|
||||
'--registry-enabled')
|
||||
expected_args = \
|
||||
self._get_expected_args(name='test', image_id='test_image',
|
||||
keypair_id='test_keypair', coe='swarm',
|
||||
external_network_id='test_net',
|
||||
network_driver='test_driver',
|
||||
registry_enabled=True)
|
||||
mock_create.assert_called_with(**expected_args)
|
||||
|
||||
@mock.patch('magnumclient.v1.baymodels.BayModelManager.create')
|
||||
def test_baymodel_create_public_success(self, mock_create):
|
||||
self._test_arg_success('baymodel-create '
|
||||
'--name test --network-driver test_driver '
|
||||
'--keypair-id test_keypair '
|
||||
'--external-network-id test_net '
|
||||
'--image-id test_image '
|
||||
'--coe swarm '
|
||||
'--public '
|
||||
'--server-type vm')
|
||||
expected_args = \
|
||||
self._get_expected_args(name='test', image_id='test_image',
|
||||
keypair_id='test_keypair', coe='swarm',
|
||||
external_network_id='test_net',
|
||||
public=True, server_type='vm',
|
||||
network_driver='test_driver')
|
||||
mock_create.assert_called_with(**expected_args)
|
||||
|
||||
@mock.patch('magnumclient.v1.baymodels.BayModelManager.create')
|
||||
def test_baymodel_create_success_with_master_flavor(self, mock_create):
|
||||
self._test_arg_success('baymodel-create '
|
||||
'--name test '
|
||||
'--image-id test_image '
|
||||
'--keypair-id test_keypair '
|
||||
'--external-network-id test_net '
|
||||
'--coe swarm '
|
||||
'--dns-nameserver test_dns '
|
||||
'--master-flavor-id test_flavor')
|
||||
expected_args = \
|
||||
self._get_expected_args(name='test', image_id='test_image',
|
||||
keypair_id='test_keypair', coe='swarm',
|
||||
external_network_id='test_net',
|
||||
dns_nameserver='test_dns',
|
||||
master_flavor_id='test_flavor')
|
||||
mock_create.assert_called_with(**expected_args)
|
||||
|
||||
@mock.patch('magnumclient.v1.baymodels.BayModelManager.create')
|
||||
def test_baymodel_create_docker_vol_size_success(self, mock_create):
|
||||
self._test_arg_success('baymodel-create '
|
||||
'--name test --docker-volume-size 4514 '
|
||||
'--keypair-id test_keypair '
|
||||
'--external-network-id test_net '
|
||||
'--image-id test_image '
|
||||
'--coe swarm '
|
||||
'--server-type vm')
|
||||
expected_args = \
|
||||
self._get_expected_args(name='test', image_id='test_image',
|
||||
keypair_id='test_keypair', coe='swarm',
|
||||
external_network_id='test_net',
|
||||
server_type='vm',
|
||||
docker_volume_size=4514)
|
||||
mock_create.assert_called_with(**expected_args)
|
||||
|
||||
@mock.patch('magnumclient.v1.baymodels.BayModelManager.create')
|
||||
def test_baymodel_create_docker_storage_driver_success(self, mock_create):
|
||||
self._test_arg_success('baymodel-create '
|
||||
'--name test '
|
||||
'--keypair-id test_keypair '
|
||||
'--external-network-id test_net '
|
||||
'--image-id test_image '
|
||||
'--docker-storage-driver devicemapper '
|
||||
'--coe swarm'
|
||||
)
|
||||
expected_args = \
|
||||
self._get_expected_args(name='test', image_id='test_image',
|
||||
keypair_id='test_keypair', coe='swarm',
|
||||
external_network_id='test_net',
|
||||
docker_storage_driver='devicemapper')
|
||||
mock_create.assert_called_with(**expected_args)
|
||||
|
||||
@mock.patch('magnumclient.v1.baymodels.BayModelManager.create')
|
||||
def test_baymodel_create_fixed_network_success(self, mock_create):
|
||||
self._test_arg_success('baymodel-create '
|
||||
'--name test --fixed-network private '
|
||||
'--keypair-id test_keypair '
|
||||
'--external-network-id test_net '
|
||||
'--image-id test_image '
|
||||
'--coe swarm '
|
||||
'--server-type vm')
|
||||
expected_args = \
|
||||
self._get_expected_args(name='test', image_id='test_image',
|
||||
keypair_id='test_keypair', coe='swarm',
|
||||
fixed_network='private',
|
||||
external_network_id='test_net',
|
||||
server_type='vm')
|
||||
mock_create.assert_called_with(**expected_args)
|
||||
|
||||
@mock.patch('magnumclient.v1.baymodels.BayModelManager.create')
|
||||
def test_baymodel_create_network_driver_success(self, mock_create):
|
||||
self._test_arg_success('baymodel-create '
|
||||
'--name test --network-driver test_driver '
|
||||
'--keypair-id test_keypair '
|
||||
'--external-network-id test_net '
|
||||
'--image-id test_image '
|
||||
'--coe swarm '
|
||||
'--server-type vm')
|
||||
expected_args = \
|
||||
self._get_expected_args(name='test', image_id='test_image',
|
||||
keypair_id='test_keypair', coe='swarm',
|
||||
external_network_id='test_net',
|
||||
server_type='vm',
|
||||
network_driver='test_driver')
|
||||
mock_create.assert_called_with(**expected_args)
|
||||
|
||||
@mock.patch('magnumclient.v1.baymodels.BayModelManager.create')
|
||||
def test_baymodel_create_volume_driver_success(self, mock_create):
|
||||
self._test_arg_success('baymodel-create '
|
||||
'--name test --volume-driver test_volume '
|
||||
'--keypair-id test_keypair '
|
||||
'--external-network-id test_net '
|
||||
'--image-id test_image '
|
||||
'--coe swarm '
|
||||
'--server-type vm')
|
||||
expected_args = \
|
||||
self._get_expected_args(name='test', image_id='test_image',
|
||||
keypair_id='test_keypair', coe='swarm',
|
||||
external_network_id='test_net',
|
||||
server_type='vm',
|
||||
volume_driver='test_volume')
|
||||
mock_create.assert_called_with(**expected_args)
|
||||
|
||||
@mock.patch('magnumclient.v1.baymodels.BayModelManager.create')
|
||||
def test_baymodel_create_http_proxy_success(self, mock_create):
|
||||
self._test_arg_success('baymodel-create '
|
||||
'--name test --fixed-network private '
|
||||
'--keypair-id test_keypair '
|
||||
'--external-network-id test_net '
|
||||
'--image-id test_image '
|
||||
'--coe swarm '
|
||||
'--http-proxy http_proxy '
|
||||
'--server-type vm')
|
||||
expected_args = \
|
||||
self._get_expected_args(name='test', image_id='test_image',
|
||||
keypair_id='test_keypair', coe='swarm',
|
||||
external_network_id='test_net',
|
||||
fixed_network='private',
|
||||
server_type='vm',
|
||||
http_proxy='http_proxy')
|
||||
mock_create.assert_called_with(**expected_args)
|
||||
|
||||
@mock.patch('magnumclient.v1.baymodels.BayModelManager.create')
|
||||
def test_baymodel_create_https_proxy_success(self, mock_create):
|
||||
self._test_arg_success('baymodel-create '
|
||||
'--name test --fixed-network private '
|
||||
'--keypair-id test_keypair '
|
||||
'--external-network-id test_net '
|
||||
'--image-id test_image '
|
||||
'--coe swarm '
|
||||
'--https-proxy https_proxy '
|
||||
'--server-type vm')
|
||||
expected_args = \
|
||||
self._get_expected_args(name='test', image_id='test_image',
|
||||
keypair_id='test_keypair', coe='swarm',
|
||||
external_network_id='test_net',
|
||||
fixed_network='private',
|
||||
server_type='vm',
|
||||
https_proxy='https_proxy')
|
||||
mock_create.assert_called_with(**expected_args)
|
||||
|
||||
@mock.patch('magnumclient.v1.baymodels.BayModelManager.create')
|
||||
def test_baymodel_create_no_proxy_success(self, mock_create):
|
||||
self._test_arg_success('baymodel-create '
|
||||
'--name test --fixed-network private '
|
||||
'--keypair-id test_keypair '
|
||||
'--external-network-id test_net '
|
||||
'--image-id test_image '
|
||||
'--coe swarm '
|
||||
'--no-proxy no_proxy '
|
||||
'--server-type vm')
|
||||
expected_args = \
|
||||
self._get_expected_args(name='test', image_id='test_image',
|
||||
keypair_id='test_keypair', coe='swarm',
|
||||
external_network_id='test_net',
|
||||
fixed_network='private',
|
||||
server_type='vm',
|
||||
no_proxy='no_proxy')
|
||||
mock_create.assert_called_with(**expected_args)
|
||||
|
||||
@mock.patch('magnumclient.v1.baymodels.BayModelManager.create')
|
||||
def test_baymodel_create_labels_success(self, mock_create):
|
||||
self._test_arg_success('baymodel-create '
|
||||
'--name test '
|
||||
'--labels key=val '
|
||||
'--keypair-id test_keypair '
|
||||
'--external-network-id test_net '
|
||||
'--image-id test_image '
|
||||
'--coe swarm '
|
||||
'--server-type vm')
|
||||
expected_args = \
|
||||
self._get_expected_args(name='test', image_id='test_image',
|
||||
keypair_id='test_keypair', coe='swarm',
|
||||
external_network_id='test_net',
|
||||
server_type='vm',
|
||||
labels={'key': 'val'})
|
||||
mock_create.assert_called_with(**expected_args)
|
||||
|
||||
@mock.patch('magnumclient.v1.baymodels.BayModelManager.create')
|
||||
def test_baymodel_create_separate_labels_success(self, mock_create):
|
||||
self._test_arg_success('baymodel-create '
|
||||
'--name test '
|
||||
'--labels key1=val1 '
|
||||
'--labels key2=val2 '
|
||||
'--keypair-id test_keypair '
|
||||
'--external-network-id test_net '
|
||||
'--image-id test_image '
|
||||
'--coe swarm '
|
||||
'--server-type vm')
|
||||
expected_args = \
|
||||
self._get_expected_args(name='test', image_id='test_image',
|
||||
keypair_id='test_keypair', coe='swarm',
|
||||
external_network_id='test_net',
|
||||
server_type='vm',
|
||||
labels={'key1': 'val1', 'key2': 'val2'})
|
||||
mock_create.assert_called_with(**expected_args)
|
||||
|
||||
@mock.patch('magnumclient.v1.baymodels.BayModelManager.create')
|
||||
def test_baymodel_create_combined_labels_success(self, mock_create):
|
||||
self._test_arg_success('baymodel-create '
|
||||
'--name test '
|
||||
'--labels key1=val1,key2=val2 '
|
||||
'--keypair-id test_keypair '
|
||||
'--external-network-id test_net '
|
||||
'--image-id test_image '
|
||||
'--coe swarm '
|
||||
'--server-type vm')
|
||||
expected_args = \
|
||||
self._get_expected_args(name='test', image_id='test_image',
|
||||
keypair_id='test_keypair', coe='swarm',
|
||||
external_network_id='test_net',
|
||||
server_type='vm',
|
||||
labels={'key1': 'val1', 'key2': 'val2'})
|
||||
mock_create.assert_called_with(**expected_args)
|
||||
|
||||
@mock.patch('magnumclient.v1.baymodels.BayModelManager.create')
|
||||
def test_baymodel_create_failure_few_arg(self, mock_create):
|
||||
self._test_arg_failure('baymodel-create '
|
||||
'--name test', self._mandatory_arg_error)
|
||||
mock_create.assert_not_called()
|
||||
|
||||
self._test_arg_failure('baymodel-create '
|
||||
'--image-id test', self._mandatory_arg_error)
|
||||
mock_create.assert_not_called()
|
||||
|
||||
self._test_arg_failure('baymodel-create '
|
||||
'--keypair-id test', self._mandatory_arg_error)
|
||||
mock_create.assert_not_called()
|
||||
|
||||
self._test_arg_failure('baymodel-create '
|
||||
'--external-network-id test',
|
||||
self._mandatory_arg_error)
|
||||
mock_create.assert_not_called()
|
||||
|
||||
self._test_arg_failure('baymodel-create '
|
||||
'--coe test', self._mandatory_arg_error)
|
||||
mock_create.assert_not_called()
|
||||
|
||||
self._test_arg_failure('baymodel-create '
|
||||
'--server-type test', self._mandatory_arg_error)
|
||||
mock_create.assert_not_called()
|
||||
|
||||
self._test_arg_failure('baymodel-create', self._mandatory_arg_error)
|
||||
mock_create.assert_not_called()
|
||||
|
||||
@mock.patch('magnumclient.v1.baymodels.BayModelManager.get')
|
||||
def test_baymodel_show_success(self, mock_show):
|
||||
self._test_arg_success('baymodel-show xxx')
|
||||
mock_show.assert_called_once_with('xxx')
|
||||
|
||||
@mock.patch('magnumclient.v1.baymodels.BayModelManager.get')
|
||||
def test_baymodel_show_failure_no_arg(self, mock_show):
|
||||
self._test_arg_failure('baymodel-show', self._few_argument_error)
|
||||
mock_show.assert_not_called()
|
||||
|
||||
@mock.patch('magnumclient.v1.baymodels.BayModelManager.delete')
|
||||
def test_baymodel_delete_success(self, mock_delete):
|
||||
self._test_arg_success('baymodel-delete xxx')
|
||||
mock_delete.assert_called_once_with('xxx')
|
||||
|
||||
@mock.patch('magnumclient.v1.baymodels.BayModelManager.delete')
|
||||
def test_baymodel_delete_multiple_id_success(self, mock_delete):
|
||||
self._test_arg_success('baymodel-delete xxx xyz')
|
||||
calls = [mock.call('xxx'), mock.call('xyz')]
|
||||
mock_delete.assert_has_calls(calls)
|
||||
|
||||
@mock.patch('magnumclient.v1.baymodels.BayModelManager.delete')
|
||||
def test_baymodel_delete_failure_no_arg(self, mock_delete):
|
||||
self._test_arg_failure('baymodel-delete', self._few_argument_error)
|
||||
mock_delete.assert_not_called()
|
||||
|
||||
@mock.patch('magnumclient.v1.baymodels.BayModelManager.update')
|
||||
def test_baymodel_update_success(self, mock_update):
|
||||
self._test_arg_success('baymodel-update test add test=test')
|
||||
patch = [{'op': 'add', 'path': '/test', 'value': 'test'}]
|
||||
mock_update.assert_called_once_with('test', patch)
|
||||
|
||||
@mock.patch('magnumclient.v1.baymodels.BayModelManager.update')
|
||||
def test_baymodel_update_success_many_attribute(self, mock_update):
|
||||
self._test_arg_success('baymodel-update test '
|
||||
'add test=test test1=test1')
|
||||
patch = [{'op': 'add', 'path': '/test', 'value': 'test'},
|
||||
{'op': 'add', 'path': '/test1', 'value': 'test1'}]
|
||||
mock_update.assert_called_once_with('test', patch)
|
||||
|
||||
@mock.patch('magnumclient.v1.baymodels.BayModelManager.update')
|
||||
def test_baymodel_update_failure_wrong_op(self, mock_update):
|
||||
_error_msg = [
|
||||
'.*?^usage: magnum baymodel-update ',
|
||||
'.*?^error: argument <op>: invalid choice: ',
|
||||
".*?^Try 'magnum help baymodel-update' for more information."
|
||||
]
|
||||
self._test_arg_failure('baymodel-update test wrong test=test',
|
||||
_error_msg)
|
||||
mock_update.assert_not_called()
|
||||
|
||||
@mock.patch('magnumclient.v1.baymodels.BayModelManager.update')
|
||||
def test_baymodel_update_failure_few_args(self, mock_update):
|
||||
_error_msg = [
|
||||
'.*?^usage: magnum baymodel-update ',
|
||||
'.*?^error: (the following arguments|too few arguments)',
|
||||
".*?^Try 'magnum help baymodel-update' for more information."
|
||||
]
|
||||
self._test_arg_failure('baymodel-update', _error_msg)
|
||||
mock_update.assert_not_called()
|
||||
|
||||
self._test_arg_failure('baymodel-update test', _error_msg)
|
||||
mock_update.assert_not_called()
|
||||
|
||||
@mock.patch('magnumclient.v1.baymodels.BayModelManager.list')
|
||||
def test_baymodel_list_success(self, mock_list):
|
||||
self._test_arg_success('baymodel-list')
|
||||
expected_args = self._get_expected_args_list()
|
||||
mock_list.assert_called_once_with(**expected_args)
|
||||
|
||||
@mock.patch('magnumclient.v1.baymodels.BayModelManager.list')
|
||||
def test_baymodel_list_success_with_arg(self, mock_list):
|
||||
self._test_arg_success('baymodel-list '
|
||||
'--limit 1 '
|
||||
'--sort-dir asc '
|
||||
'--sort-key uuid')
|
||||
expected_args = self._get_expected_args_list(1, 'asc', 'uuid')
|
||||
mock_list.assert_called_once_with(**expected_args)
|
||||
|
||||
@mock.patch('magnumclient.v1.baymodels.BayModelManager.list')
|
||||
def test_baymodel_list_success_detailed(self, mock_list):
|
||||
self._test_arg_success('baymodel-list '
|
||||
'--detail')
|
||||
expected_args = self._get_expected_args_list(detail=True)
|
||||
mock_list.assert_called_once_with(**expected_args)
|
||||
|
||||
@mock.patch('magnumclient.v1.baymodels.BayModelManager.list')
|
||||
def test_baymodel_list_ignored_duplicated_field(self, mock_list):
|
||||
mock_list.return_value = [FakeBayModel()]
|
||||
self._test_arg_success('baymodel-list --fields coe,coe,coe,name,name',
|
||||
keyword='\n| uuid | name | Coe |\n')
|
||||
# Output should be
|
||||
# +------+------+-----+
|
||||
# | uuid | name | Coe |
|
||||
# +------+------+-----+
|
||||
# | x | x | x |
|
||||
# +------+------+-----+
|
||||
expected_args = self._get_expected_args_list()
|
||||
mock_list.assert_called_once_with(**expected_args)
|
||||
|
||||
@mock.patch('magnumclient.v1.baymodels.BayModelManager.list')
|
||||
def test_baymodel_list_failure_with_invalid_field(self, mock_list):
|
||||
mock_list.return_value = [FakeBayModel()]
|
||||
_error_msg = [".*?^Non-existent fields are specified: ['xxx','zzz']"]
|
||||
self.assertRaises(exceptions.CommandError,
|
||||
self._test_arg_failure,
|
||||
'baymodel-list --fields xxx,coe,zzz',
|
||||
_error_msg)
|
||||
expected_args = self._get_expected_args_list()
|
||||
mock_list.assert_called_once_with(**expected_args)
|
||||
|
||||
@mock.patch('magnumclient.v1.baymodels.BayModelManager.list')
|
||||
def test_baymodel_list_failure_invalid_arg(self, mock_list):
|
||||
_error_msg = [
|
||||
'.*?^usage: magnum baymodel-list ',
|
||||
'.*?^error: argument --sort-dir: invalid choice: ',
|
||||
".*?^Try 'magnum help baymodel-list' for more information."
|
||||
]
|
||||
self._test_arg_failure('baymodel-list --sort-dir aaa', _error_msg)
|
||||
mock_list.assert_not_called()
|
||||
|
||||
@mock.patch('magnumclient.v1.baymodels.BayModelManager.list')
|
||||
def test_baymodel_list_failure(self, mock_list):
|
||||
self._test_arg_failure('baymodel-list --wrong',
|
||||
self._unrecognized_arg_error)
|
||||
mock_list.assert_not_called()
|
@ -1,317 +0,0 @@
|
||||
# Copyright 2015 IBM Corp.
|
||||
#
|
||||
# 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.
|
||||
|
||||
import copy
|
||||
|
||||
import testtools
|
||||
from testtools import matchers
|
||||
|
||||
from magnumclient import exceptions
|
||||
from magnumclient.tests import utils
|
||||
from magnumclient.v1 import bays
|
||||
|
||||
|
||||
BAY1 = {'id': 123,
|
||||
'uuid': '66666666-7777-8888-9999-000000000001',
|
||||
'name': 'bay1',
|
||||
'baymodel_id': 'e74c40e0-d825-11e2-a28f-0800200c9a61',
|
||||
'stack_id': '5d12f6fd-a196-4bf0-ae4c-1f639a523a51',
|
||||
'api_address': '172.17.2.1',
|
||||
'node_addresses': ['172.17.2.3'],
|
||||
'node_count': 2,
|
||||
'master_count': 1,
|
||||
}
|
||||
BAY2 = {'id': 124,
|
||||
'uuid': '66666666-7777-8888-9999-000000000002',
|
||||
'name': 'bay2',
|
||||
'baymodel_id': 'e74c40e0-d825-11e2-a28f-0800200c9a62',
|
||||
'stack_id': '5d12f6fd-a196-4bf0-ae4c-1f639a523a52',
|
||||
'api_address': '172.17.2.2',
|
||||
'node_addresses': ['172.17.2.4'],
|
||||
'node_count': 2,
|
||||
'master_count': 1,
|
||||
}
|
||||
|
||||
CREATE_BAY = copy.deepcopy(BAY1)
|
||||
del CREATE_BAY['id']
|
||||
del CREATE_BAY['uuid']
|
||||
del CREATE_BAY['stack_id']
|
||||
del CREATE_BAY['api_address']
|
||||
del CREATE_BAY['node_addresses']
|
||||
|
||||
UPDATED_BAY = copy.deepcopy(BAY1)
|
||||
NEW_NAME = 'newbay'
|
||||
UPDATED_BAY['name'] = NEW_NAME
|
||||
|
||||
fake_responses = {
|
||||
'/v1/bays':
|
||||
{
|
||||
'GET': (
|
||||
{},
|
||||
{'bays': [BAY1, BAY2]},
|
||||
),
|
||||
'POST': (
|
||||
{},
|
||||
CREATE_BAY,
|
||||
),
|
||||
},
|
||||
'/v1/bays/%s' % BAY1['id']:
|
||||
{
|
||||
'GET': (
|
||||
{},
|
||||
BAY1
|
||||
),
|
||||
'DELETE': (
|
||||
{},
|
||||
None,
|
||||
),
|
||||
'PATCH': (
|
||||
{},
|
||||
UPDATED_BAY,
|
||||
),
|
||||
},
|
||||
'/v1/bays/%s/?rollback=True' % BAY1['id']:
|
||||
{
|
||||
'PATCH': (
|
||||
{},
|
||||
UPDATED_BAY,
|
||||
),
|
||||
},
|
||||
'/v1/bays/%s' % BAY1['name']:
|
||||
{
|
||||
'GET': (
|
||||
{},
|
||||
BAY1
|
||||
),
|
||||
'DELETE': (
|
||||
{},
|
||||
None,
|
||||
),
|
||||
'PATCH': (
|
||||
{},
|
||||
UPDATED_BAY,
|
||||
),
|
||||
},
|
||||
'/v1/bays/?limit=2':
|
||||
{
|
||||
'GET': (
|
||||
{},
|
||||
{'bays': [BAY1, BAY2]},
|
||||
),
|
||||
},
|
||||
'/v1/bays/?marker=%s' % BAY2['uuid']:
|
||||
{
|
||||
'GET': (
|
||||
{},
|
||||
{'bays': [BAY1, BAY2]},
|
||||
),
|
||||
},
|
||||
'/v1/bays/?limit=2&marker=%s' % BAY2['uuid']:
|
||||
{
|
||||
'GET': (
|
||||
{},
|
||||
{'bays': [BAY1, BAY2]},
|
||||
),
|
||||
},
|
||||
'/v1/bays/?sort_dir=asc':
|
||||
{
|
||||
'GET': (
|
||||
{},
|
||||
{'bays': [BAY1, BAY2]},
|
||||
),
|
||||
},
|
||||
'/v1/bays/?sort_key=uuid':
|
||||
{
|
||||
'GET': (
|
||||
{},
|
||||
{'bays': [BAY1, BAY2]},
|
||||
),
|
||||
},
|
||||
'/v1/bays/?sort_key=uuid&sort_dir=desc':
|
||||
{
|
||||
'GET': (
|
||||
{},
|
||||
{'bays': [BAY2, BAY1]},
|
||||
),
|
||||
},
|
||||
}
|
||||
|
||||
|
||||
class BayManagerTest(testtools.TestCase):
|
||||
|
||||
def setUp(self):
|
||||
super(BayManagerTest, self).setUp()
|
||||
self.api = utils.FakeAPI(fake_responses)
|
||||
self.mgr = bays.BayManager(self.api)
|
||||
|
||||
def test_bay_list(self):
|
||||
bays = self.mgr.list()
|
||||
expect = [
|
||||
('GET', '/v1/bays', {}, None),
|
||||
]
|
||||
self.assertEqual(expect, self.api.calls)
|
||||
self.assertThat(bays, matchers.HasLength(2))
|
||||
|
||||
def _test_bay_list_with_filters(self, limit=None, marker=None,
|
||||
sort_key=None, sort_dir=None,
|
||||
detail=False, expect=[]):
|
||||
bays_filter = self.mgr.list(limit=limit, marker=marker,
|
||||
sort_key=sort_key,
|
||||
sort_dir=sort_dir,
|
||||
detail=detail)
|
||||
self.assertEqual(expect, self.api.calls)
|
||||
self.assertThat(bays_filter, matchers.HasLength(2))
|
||||
|
||||
def test_bay_list_with_limit(self):
|
||||
expect = [
|
||||
('GET', '/v1/bays/?limit=2', {}, None),
|
||||
]
|
||||
self._test_bay_list_with_filters(
|
||||
limit=2,
|
||||
expect=expect)
|
||||
|
||||
def test_bay_list_with_marker(self):
|
||||
expect = [
|
||||
('GET', '/v1/bays/?marker=%s' % BAY2['uuid'], {}, None),
|
||||
]
|
||||
self._test_bay_list_with_filters(
|
||||
marker=BAY2['uuid'],
|
||||
expect=expect)
|
||||
|
||||
def test_bay_list_with_marker_limit(self):
|
||||
expect = [
|
||||
('GET', '/v1/bays/?limit=2&marker=%s' % BAY2['uuid'], {}, None),
|
||||
]
|
||||
self._test_bay_list_with_filters(
|
||||
limit=2, marker=BAY2['uuid'],
|
||||
expect=expect)
|
||||
|
||||
def test_bay_list_with_sort_dir(self):
|
||||
expect = [
|
||||
('GET', '/v1/bays/?sort_dir=asc', {}, None),
|
||||
]
|
||||
self._test_bay_list_with_filters(
|
||||
sort_dir='asc',
|
||||
expect=expect)
|
||||
|
||||
def test_bay_list_with_sort_key(self):
|
||||
expect = [
|
||||
('GET', '/v1/bays/?sort_key=uuid', {}, None),
|
||||
]
|
||||
self._test_bay_list_with_filters(
|
||||
sort_key='uuid',
|
||||
expect=expect)
|
||||
|
||||
def test_bay_list_with_sort_key_dir(self):
|
||||
expect = [
|
||||
('GET', '/v1/bays/?sort_key=uuid&sort_dir=desc', {}, None),
|
||||
]
|
||||
self._test_bay_list_with_filters(
|
||||
sort_key='uuid', sort_dir='desc',
|
||||
expect=expect)
|
||||
|
||||
def test_bay_show_by_id(self):
|
||||
bay = self.mgr.get(BAY1['id'])
|
||||
expect = [
|
||||
('GET', '/v1/bays/%s' % BAY1['id'], {}, None)
|
||||
]
|
||||
self.assertEqual(expect, self.api.calls)
|
||||
self.assertEqual(BAY1['name'], bay.name)
|
||||
self.assertEqual(BAY1['baymodel_id'], bay.baymodel_id)
|
||||
|
||||
def test_bay_show_by_name(self):
|
||||
bay = self.mgr.get(BAY1['name'])
|
||||
expect = [
|
||||
('GET', '/v1/bays/%s' % BAY1['name'], {}, None)
|
||||
]
|
||||
self.assertEqual(expect, self.api.calls)
|
||||
self.assertEqual(BAY1['name'], bay.name)
|
||||
self.assertEqual(BAY1['baymodel_id'], bay.baymodel_id)
|
||||
|
||||
def test_bay_create(self):
|
||||
bay = self.mgr.create(**CREATE_BAY)
|
||||
expect = [
|
||||
('POST', '/v1/bays', {}, CREATE_BAY),
|
||||
]
|
||||
self.assertEqual(expect, self.api.calls)
|
||||
self.assertTrue(bay)
|
||||
|
||||
def test_bay_create_with_discovery_url(self):
|
||||
bay_with_discovery = dict()
|
||||
bay_with_discovery.update(CREATE_BAY)
|
||||
bay_with_discovery['discovery_url'] = 'discovery_url'
|
||||
bay = self.mgr.create(**bay_with_discovery)
|
||||
expect = [
|
||||
('POST', '/v1/bays', {}, bay_with_discovery),
|
||||
]
|
||||
self.assertEqual(expect, self.api.calls)
|
||||
self.assertTrue(bay)
|
||||
|
||||
def test_bay_create_with_bay_create_timeout(self):
|
||||
bay_with_timeout = dict()
|
||||
bay_with_timeout.update(CREATE_BAY)
|
||||
bay_with_timeout['bay_create_timeout'] = '15'
|
||||
bay = self.mgr.create(**bay_with_timeout)
|
||||
expect = [
|
||||
('POST', '/v1/bays', {}, bay_with_timeout),
|
||||
]
|
||||
self.assertEqual(expect, self.api.calls)
|
||||
self.assertTrue(bay)
|
||||
|
||||
def test_bay_create_fail(self):
|
||||
CREATE_BAY_FAIL = copy.deepcopy(CREATE_BAY)
|
||||
CREATE_BAY_FAIL["wrong_key"] = "wrong"
|
||||
self.assertRaisesRegex(exceptions.InvalidAttribute,
|
||||
("Key must be in %s" %
|
||||
','.join(bays.CREATION_ATTRIBUTES)),
|
||||
self.mgr.create, **CREATE_BAY_FAIL)
|
||||
self.assertEqual([], self.api.calls)
|
||||
|
||||
def test_bay_delete_by_id(self):
|
||||
bay = self.mgr.delete(BAY1['id'])
|
||||
expect = [
|
||||
('DELETE', '/v1/bays/%s' % BAY1['id'], {}, None),
|
||||
]
|
||||
self.assertEqual(expect, self.api.calls)
|
||||
self.assertIsNone(bay)
|
||||
|
||||
def test_bay_delete_by_name(self):
|
||||
bay = self.mgr.delete(BAY1['name'])
|
||||
expect = [
|
||||
('DELETE', '/v1/bays/%s' % BAY1['name'], {}, None),
|
||||
]
|
||||
self.assertEqual(expect, self.api.calls)
|
||||
self.assertIsNone(bay)
|
||||
|
||||
def test_bay_update(self):
|
||||
patch = {'op': 'replace',
|
||||
'value': NEW_NAME,
|
||||
'path': '/name'}
|
||||
bay = self.mgr.update(id=BAY1['id'], patch=patch)
|
||||
expect = [
|
||||
('PATCH', '/v1/bays/%s' % BAY1['id'], {}, patch),
|
||||
]
|
||||
self.assertEqual(expect, self.api.calls)
|
||||
self.assertEqual(NEW_NAME, bay.name)
|
||||
|
||||
def test_bay_update_with_rollback(self):
|
||||
patch = {'op': 'replace',
|
||||
'value': NEW_NAME,
|
||||
'path': '/name'}
|
||||
bay = self.mgr.update(id=BAY1['id'], patch=patch, rollback=True)
|
||||
expect = [
|
||||
('PATCH', '/v1/bays/%s/?rollback=True' % BAY1['id'], {}, patch),
|
||||
]
|
||||
self.assertEqual(expect, self.api.calls)
|
||||
self.assertEqual(NEW_NAME, bay.name)
|
@ -1,403 +0,0 @@
|
||||
# Copyright 2015 NEC Corporation. All rights reserved.
|
||||
#
|
||||
# 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.
|
||||
|
||||
from unittest import mock
|
||||
|
||||
from magnumclient import exceptions
|
||||
from magnumclient.tests.v1 import shell_test_base
|
||||
from magnumclient.tests.v1 import test_baymodels_shell
|
||||
from magnumclient.v1.bays import Bay
|
||||
|
||||
|
||||
class FakeBay(Bay):
|
||||
def __init__(self, manager=None, info={}, **kwargs):
|
||||
Bay.__init__(self, manager=manager, info=info)
|
||||
self.uuid = kwargs.get('uuid', 'x')
|
||||
self.name = kwargs.get('name', 'x')
|
||||
self.baymodel_id = kwargs.get('baymodel_id', 'x')
|
||||
self.stack_id = kwargs.get('stack_id', 'x')
|
||||
self.status = kwargs.get('status', 'x')
|
||||
self.master_count = kwargs.get('master_count', 1)
|
||||
self.node_count = kwargs.get('node_count', 1)
|
||||
self.links = kwargs.get('links', [])
|
||||
self.bay_create_timeout = kwargs.get('bay_create_timeout', 60)
|
||||
|
||||
|
||||
class FakeCert(object):
|
||||
def __init__(self, pem):
|
||||
self.pem = pem
|
||||
|
||||
|
||||
class ShellTest(shell_test_base.TestCommandLineArgument):
|
||||
|
||||
def _get_expected_args_list(self, marker=None, limit=None,
|
||||
sort_dir=None, sort_key=None):
|
||||
expected_args = {}
|
||||
expected_args['marker'] = marker
|
||||
expected_args['limit'] = limit
|
||||
expected_args['sort_dir'] = sort_dir
|
||||
expected_args['sort_key'] = sort_key
|
||||
|
||||
return expected_args
|
||||
|
||||
def _get_expected_args_create(self, baymodel_id, name=None,
|
||||
master_count=1, node_count=1,
|
||||
bay_create_timeout=60,
|
||||
discovery_url=None):
|
||||
expected_args = {}
|
||||
expected_args['name'] = name
|
||||
expected_args['baymodel_id'] = baymodel_id
|
||||
expected_args['master_count'] = master_count
|
||||
expected_args['node_count'] = node_count
|
||||
expected_args['bay_create_timeout'] = bay_create_timeout
|
||||
expected_args['discovery_url'] = discovery_url
|
||||
|
||||
return expected_args
|
||||
|
||||
@mock.patch('magnumclient.v1.bays.BayManager.list')
|
||||
def test_bay_list_success(self, mock_list):
|
||||
self._test_arg_success('bay-list')
|
||||
expected_args = self._get_expected_args_list()
|
||||
mock_list.assert_called_once_with(**expected_args)
|
||||
|
||||
@mock.patch('magnumclient.v1.bays.BayManager.list')
|
||||
def test_bay_list_success_with_arg(self, mock_list):
|
||||
self._test_arg_success('bay-list '
|
||||
'--marker some_uuid '
|
||||
'--limit 1 '
|
||||
'--sort-dir asc '
|
||||
'--sort-key uuid')
|
||||
expected_args = self._get_expected_args_list('some_uuid', 1,
|
||||
'asc', 'uuid')
|
||||
mock_list.assert_called_once_with(**expected_args)
|
||||
|
||||
@mock.patch('magnumclient.v1.bays.BayManager.list')
|
||||
def test_bay_list_ignored_duplicated_field(self, mock_list):
|
||||
mock_list.return_value = [FakeBay()]
|
||||
self._test_arg_success('bay-list --fields status,status,status,name',
|
||||
keyword=('\n| uuid | name | node_count | '
|
||||
'master_count | status |\n'))
|
||||
# Output should be
|
||||
# +------+------+------------+--------------+--------+
|
||||
# | uuid | name | node_count | master_count | status |
|
||||
# +------+------+------------+--------------+--------+
|
||||
# | x | x | x | x | x |
|
||||
# +------+------+------------+--------------+--------+
|
||||
expected_args = self._get_expected_args_list()
|
||||
mock_list.assert_called_once_with(**expected_args)
|
||||
|
||||
@mock.patch('magnumclient.v1.bays.BayManager.list')
|
||||
def test_bay_list_failure_with_invalid_field(self, mock_list):
|
||||
mock_list.return_value = [FakeBay()]
|
||||
_error_msg = [".*?^Non-existent fields are specified: ['xxx','zzz']"]
|
||||
self.assertRaises(exceptions.CommandError,
|
||||
self._test_arg_failure,
|
||||
'bay-list --fields xxx,stack_id,zzz,status',
|
||||
_error_msg)
|
||||
expected_args = self._get_expected_args_list()
|
||||
mock_list.assert_called_once_with(**expected_args)
|
||||
|
||||
@mock.patch('magnumclient.v1.bays.BayManager.list')
|
||||
def test_bay_list_failure_invalid_arg(self, mock_list):
|
||||
_error_msg = [
|
||||
'.*?^usage: magnum bay-list ',
|
||||
'.*?^error: argument --sort-dir: invalid choice: ',
|
||||
".*?^Try 'magnum help bay-list' for more information."
|
||||
]
|
||||
self._test_arg_failure('bay-list --sort-dir aaa', _error_msg)
|
||||
mock_list.assert_not_called()
|
||||
|
||||
@mock.patch('magnumclient.v1.bays.BayManager.list')
|
||||
def test_bay_list_failure(self, mock_list):
|
||||
self._test_arg_failure('bay-list --wrong',
|
||||
self._unrecognized_arg_error)
|
||||
mock_list.assert_not_called()
|
||||
|
||||
@mock.patch('magnumclient.v1.baymodels.BayModelManager.get')
|
||||
@mock.patch('magnumclient.v1.bays.BayManager.create')
|
||||
def test_bay_create_success(self, mock_create, mock_get):
|
||||
mock_baymodel = mock.MagicMock()
|
||||
mock_baymodel.uuid = 'xxx'
|
||||
mock_get.return_value = mock_baymodel
|
||||
self._test_arg_success('bay-create --name test --baymodel xxx '
|
||||
'--node-count 123 --timeout 15')
|
||||
expected_args = self._get_expected_args_create('xxx', name='test',
|
||||
node_count=123,
|
||||
bay_create_timeout=15)
|
||||
mock_create.assert_called_with(**expected_args)
|
||||
|
||||
self._test_arg_success('bay-create --baymodel xxx')
|
||||
expected_args = self._get_expected_args_create('xxx')
|
||||
mock_create.assert_called_with(**expected_args)
|
||||
|
||||
self._test_arg_success('bay-create --name test --baymodel xxx')
|
||||
expected_args = self._get_expected_args_create('xxx',
|
||||
name='test')
|
||||
mock_create.assert_called_with(**expected_args)
|
||||
|
||||
self._test_arg_success('bay-create --baymodel xxx --node-count 123')
|
||||
expected_args = self._get_expected_args_create('xxx',
|
||||
node_count=123)
|
||||
|
||||
self._test_arg_success('bay-create --baymodel xxx --node-count 123 '
|
||||
'--master-count 123')
|
||||
expected_args = self._get_expected_args_create('xxx',
|
||||
master_count=123,
|
||||
node_count=123)
|
||||
mock_create.assert_called_with(**expected_args)
|
||||
|
||||
self._test_arg_success('bay-create --baymodel xxx '
|
||||
'--timeout 15')
|
||||
expected_args = self._get_expected_args_create('xxx',
|
||||
bay_create_timeout=15)
|
||||
mock_create.assert_called_with(**expected_args)
|
||||
|
||||
@mock.patch('magnumclient.v1.baymodels.BayModelManager.get')
|
||||
@mock.patch('magnumclient.v1.bays.BayManager.get')
|
||||
def test_bay_show_baymodel_metadata(self, mock_bay, mock_baymodel):
|
||||
mock_bay.return_value = mock.MagicMock(baymodel_id=0)
|
||||
mock_baymodel.return_value = test_baymodels_shell.FakeBayModel(
|
||||
info={'links': 0, 'uuid': 0, 'id': 0, 'name': ''})
|
||||
|
||||
self._test_arg_success('bay-show --long x')
|
||||
mock_bay.assert_called_once_with('x')
|
||||
mock_baymodel.assert_called_once_with(0)
|
||||
|
||||
@mock.patch('magnumclient.v1.baymodels.BayModelManager.get')
|
||||
@mock.patch('magnumclient.v1.bays.BayManager.create')
|
||||
def test_bay_create_success_only_baymodel_arg(self, mock_create, mock_get):
|
||||
mock_baymodel = mock.MagicMock()
|
||||
mock_baymodel.uuid = 'xxx'
|
||||
mock_get.return_value = mock_baymodel
|
||||
self._test_arg_success('bay-create --baymodel xxx')
|
||||
expected_args = self._get_expected_args_create('xxx')
|
||||
mock_create.assert_called_with(**expected_args)
|
||||
|
||||
@mock.patch('magnumclient.v1.bays.BayManager.create')
|
||||
def test_bay_create_failure_only_name(self, mock_create):
|
||||
self._test_arg_failure('bay-create --name test',
|
||||
self._mandatory_arg_error)
|
||||
mock_create.assert_not_called()
|
||||
|
||||
@mock.patch('magnumclient.v1.bays.BayManager.create')
|
||||
def test_bay_create_failure_only_node_count(self, mock_create):
|
||||
self._test_arg_failure('bay-create --node-count 1',
|
||||
self._mandatory_arg_error)
|
||||
mock_create.assert_not_called()
|
||||
|
||||
@mock.patch('magnumclient.v1.bays.BayManager.create')
|
||||
def test_bay_create_failure_invalid_node_count(self, mock_create):
|
||||
self._test_arg_failure('bay-create --baymodel xxx --node-count test',
|
||||
self._invalid_value_error)
|
||||
mock_create.assert_not_called()
|
||||
|
||||
@mock.patch('magnumclient.v1.bays.BayManager.create')
|
||||
def test_bay_create_failure_only_bay_create_timeout(self, mock_create):
|
||||
self._test_arg_failure('bay-create --timeout 15',
|
||||
self._mandatory_arg_error)
|
||||
mock_create.assert_not_called()
|
||||
|
||||
@mock.patch('magnumclient.v1.bays.BayManager.create')
|
||||
def test_bay_create_failure_no_arg(self, mock_create):
|
||||
self._test_arg_failure('bay-create',
|
||||
self._mandatory_arg_error)
|
||||
mock_create.assert_not_called()
|
||||
|
||||
@mock.patch('magnumclient.v1.bays.BayManager.create')
|
||||
def test_bay_create_failure_invalid_master_count(self, mock_create):
|
||||
self._test_arg_failure('bay-create --baymodel xxx --master-count test',
|
||||
self._invalid_value_error)
|
||||
mock_create.assert_not_called()
|
||||
|
||||
@mock.patch('magnumclient.v1.bays.BayManager.delete')
|
||||
def test_bay_delete_success(self, mock_delete):
|
||||
self._test_arg_success('bay-delete xxx')
|
||||
mock_delete.assert_called_once_with('xxx')
|
||||
|
||||
@mock.patch('magnumclient.v1.bays.BayManager.delete')
|
||||
def test_bay_delete_multiple_id_success(self, mock_delete):
|
||||
self._test_arg_success('bay-delete xxx xyz')
|
||||
calls = [mock.call('xxx'), mock.call('xyz')]
|
||||
mock_delete.assert_has_calls(calls)
|
||||
|
||||
@mock.patch('magnumclient.v1.bays.BayManager.delete')
|
||||
def test_bay_delete_failure_no_arg(self, mock_delete):
|
||||
self._test_arg_failure('bay-delete', self._few_argument_error)
|
||||
mock_delete.assert_not_called()
|
||||
|
||||
@mock.patch('magnumclient.v1.bays.BayManager.get')
|
||||
def test_bay_show_success(self, mock_show):
|
||||
self._test_arg_success('bay-show xxx')
|
||||
mock_show.assert_called_once_with('xxx')
|
||||
|
||||
@mock.patch('magnumclient.v1.bays.BayManager.get')
|
||||
def test_bay_show_failure_no_arg(self, mock_show):
|
||||
self._test_arg_failure('bay-show', self._few_argument_error)
|
||||
mock_show.assert_not_called()
|
||||
|
||||
@mock.patch('magnumclient.v1.bays.BayManager.update')
|
||||
def test_bay_update_success(self, mock_update):
|
||||
self._test_arg_success('bay-update test add test=test')
|
||||
patch = [{'op': 'add', 'path': '/test', 'value': 'test'}]
|
||||
mock_update.assert_called_once_with('test', patch, False)
|
||||
|
||||
@mock.patch('magnumclient.v1.bays.BayManager.update')
|
||||
def test_bay_update_success_many_attribute(self, mock_update):
|
||||
self._test_arg_success('bay-update test add test=test test1=test1')
|
||||
patch = [{'op': 'add', 'path': '/test', 'value': 'test'},
|
||||
{'op': 'add', 'path': '/test1', 'value': 'test1'}]
|
||||
mock_update.assert_called_once_with('test', patch, False)
|
||||
|
||||
@mock.patch('magnumclient.v1.bays.BayManager.update')
|
||||
def test_bay_update_success_rollback(self, mock_update):
|
||||
self._test_arg_success('bay-update test add test=test --rollback')
|
||||
patch = [{'op': 'add', 'path': '/test', 'value': 'test'}]
|
||||
mock_update.assert_called_once_with('test', patch, True)
|
||||
|
||||
@mock.patch('magnumclient.v1.bays.BayManager.update')
|
||||
def test_bay_update_rollback_old_api_version(self, mock_update):
|
||||
self.assertRaises(
|
||||
exceptions.CommandError,
|
||||
self.shell,
|
||||
'--magnum-api-version 1.2 bay-update '
|
||||
'test add test=test --rollback')
|
||||
mock_update.assert_not_called()
|
||||
|
||||
@mock.patch('magnumclient.v1.bays.BayManager.update')
|
||||
def test_bay_update_failure_wrong_op(self, mock_update):
|
||||
_error_msg = [
|
||||
'.*?^usage: magnum bay-update ',
|
||||
'.*?^error: argument <op>: invalid choice: ',
|
||||
".*?^Try 'magnum help bay-update' for more information."
|
||||
]
|
||||
self._test_arg_failure('bay-update test wrong test=test', _error_msg)
|
||||
mock_update.assert_not_called()
|
||||
|
||||
@mock.patch('magnumclient.v1.bays.BayManager.update')
|
||||
def test_bay_update_failure_wrong_attribute(self, mock_update):
|
||||
_error_msg = [
|
||||
'.*?^ERROR: Attributes must be a list of PATH=VALUE'
|
||||
]
|
||||
self.assertRaises(exceptions.CommandError, self._test_arg_failure,
|
||||
'bay-update test add test', _error_msg)
|
||||
mock_update.assert_not_called()
|
||||
|
||||
@mock.patch('magnumclient.v1.bays.BayManager.update')
|
||||
def test_bay_update_failure_few_args(self, mock_update):
|
||||
_error_msg = [
|
||||
'.*?^usage: magnum bay-update ',
|
||||
'.*?^error: (the following arguments|too few arguments)',
|
||||
".*?^Try 'magnum help bay-update' for more information."
|
||||
]
|
||||
self._test_arg_failure('bay-update', _error_msg)
|
||||
mock_update.assert_not_called()
|
||||
|
||||
self._test_arg_failure('bay-update test', _error_msg)
|
||||
mock_update.assert_not_called()
|
||||
|
||||
self._test_arg_failure('bay-update test add', _error_msg)
|
||||
mock_update.assert_not_called()
|
||||
|
||||
@mock.patch('magnumclient.v1.baymodels.BayModelManager.get')
|
||||
@mock.patch('magnumclient.v1.bays.BayManager.get')
|
||||
def test_bay_config_success(self, mock_bay, mock_baymodel):
|
||||
mock_bay.return_value = FakeBay(status='UPDATE_COMPLETE')
|
||||
self._test_arg_success('bay-config xxx')
|
||||
mock_bay.assert_called_with('xxx')
|
||||
|
||||
mock_bay.return_value = FakeBay(status='CREATE_COMPLETE')
|
||||
self._test_arg_success('bay-config xxx')
|
||||
mock_bay.assert_called_with('xxx')
|
||||
|
||||
self._test_arg_success('bay-config --dir /tmp xxx')
|
||||
mock_bay.assert_called_with('xxx')
|
||||
|
||||
self._test_arg_success('bay-config --force xxx')
|
||||
mock_bay.assert_called_with('xxx')
|
||||
|
||||
self._test_arg_success('bay-config --dir /tmp --force xxx')
|
||||
mock_bay.assert_called_with('xxx')
|
||||
|
||||
@mock.patch('magnumclient.v1.bays.BayManager.get')
|
||||
def test_bay_config_failure_no_arg(self, mock_bay):
|
||||
self._test_arg_failure('bay-config', self._few_argument_error)
|
||||
mock_bay.assert_not_called()
|
||||
|
||||
@mock.patch('magnumclient.v1.bays.BayManager.get')
|
||||
def test_bay_config_failure_wrong_arg(self, mock_bay):
|
||||
self._test_arg_failure('bay-config xxx yyy',
|
||||
self._unrecognized_arg_error)
|
||||
mock_bay.assert_not_called()
|
||||
|
||||
@mock.patch('os.path.exists')
|
||||
@mock.patch('magnumclient.v1.certificates.CertificateManager.create')
|
||||
@mock.patch('magnumclient.v1.certificates.CertificateManager.get')
|
||||
@mock.patch('magnumclient.v1.baymodels.BayModelManager.get')
|
||||
@mock.patch('magnumclient.v1.bays.BayManager.get')
|
||||
def _test_bay_config_success(self, mock_bay, mock_bm, mock_cert_get,
|
||||
mock_cert_create, mock_exists, coe, shell,
|
||||
tls_disable):
|
||||
cert = FakeCert(pem='foo bar')
|
||||
mock_exists.return_value = False
|
||||
mock_bay.return_value = FakeBay(status='CREATE_COMPLETE',
|
||||
info={'name': 'Kluster',
|
||||
'api_address': '127.0.0.1'},
|
||||
baymodel_id='fake_bm',
|
||||
uuid='fake_bay')
|
||||
mock_cert_get.return_value = cert
|
||||
mock_cert_create.return_value = cert
|
||||
mock_bm.return_value = test_baymodels_shell. \
|
||||
FakeBayModel(coe=coe, name='fake_bm', tls_disabled=tls_disable)
|
||||
with mock.patch.dict('os.environ', {'SHELL': shell}):
|
||||
self._test_arg_success('bay-config test_bay')
|
||||
|
||||
self.assertTrue(mock_exists.called)
|
||||
mock_bay.assert_called_once_with('test_bay')
|
||||
mock_bm.assert_called_once_with('fake_bm')
|
||||
if not tls_disable:
|
||||
mock_cert_create.assert_called_once_with(cluster_uuid='fake_bay',
|
||||
csr=mock.ANY)
|
||||
mock_cert_get.assert_called_once_with(cluster_uuid='fake_bay')
|
||||
|
||||
def test_bay_config_swarm_success_with_tls_csh(self):
|
||||
self._test_bay_config_success(coe='swarm', shell='csh',
|
||||
tls_disable=False)
|
||||
|
||||
def test_bay_config_swarm_success_with_tls_non_csh(self):
|
||||
self._test_bay_config_success(coe='swarm', shell='zsh',
|
||||
tls_disable=False)
|
||||
|
||||
def test_bay_config_swarm_success_without_tls_csh(self):
|
||||
self._test_bay_config_success(coe='swarm', shell='csh',
|
||||
tls_disable=True)
|
||||
|
||||
def test_bay_config_swarm_success_without_tls_non_csh(self):
|
||||
self._test_bay_config_success(coe='swarm', shell='zsh',
|
||||
tls_disable=True)
|
||||
|
||||
def test_bay_config_k8s_success_with_tls_csh(self):
|
||||
self._test_bay_config_success(coe='kubernetes', shell='csh',
|
||||
tls_disable=False)
|
||||
|
||||
def test_bay_config_k8s_success_with_tls_non_csh(self):
|
||||
self._test_bay_config_success(coe='kubernetes', shell='zsh',
|
||||
tls_disable=False)
|
||||
|
||||
def test_bay_config_k8s_success_without_tls_csh(self):
|
||||
self._test_bay_config_success(coe='kubernetes', shell='csh',
|
||||
tls_disable=True)
|
||||
|
||||
def test_bay_config_k8s_success_without_tls_non_csh(self):
|
||||
self._test_bay_config_success(coe='kubernetes', shell='zsh',
|
||||
tls_disable=True)
|
@ -34,11 +34,6 @@ CERT2 = {
|
||||
CREATE_CERT = {'cluster_uuid': '5d12f6fd-a196-4bf0-ae4c-1f639a523a53',
|
||||
'csr': 'fake-csr'}
|
||||
|
||||
CREATE_BACKWARDS_CERT = {
|
||||
'bay_uuid': '5d12f6fd-a196-4bf0-ae4c-1f639a523a53',
|
||||
'csr': 'fake-csr'
|
||||
}
|
||||
|
||||
fake_responses = {
|
||||
'/v1/certificates':
|
||||
{
|
||||
@ -87,17 +82,6 @@ class CertificateManagerTest(testtools.TestCase):
|
||||
self.assertEqual(CERT2['pem'], cert.pem)
|
||||
self.assertEqual(CERT2['csr'], cert.csr)
|
||||
|
||||
def test_cert_create_backwards_compatibility(self):
|
||||
# Using a CREATION_ATTRIBUTE of bay_uuid and expecting a
|
||||
# cluster_uuid in return
|
||||
cert = self.mgr.create(**CREATE_BACKWARDS_CERT)
|
||||
expect = [
|
||||
('POST', '/v1/certificates', {}, CREATE_CERT),
|
||||
]
|
||||
self.assertEqual(expect, self.api.calls)
|
||||
self.assertEqual(CERT2['cluster_uuid'], cert.cluster_uuid)
|
||||
self.assertEqual(CERT2['csr'], cert.csr)
|
||||
|
||||
def test_create_fail(self):
|
||||
create_cert_fail = copy.deepcopy(CREATE_CERT)
|
||||
create_cert_fail["wrong_key"] = "wrong"
|
||||
|
@ -21,18 +21,6 @@ from magnumclient.v1 import certificates_shell
|
||||
|
||||
class ShellTest(shell_test_base.TestCommandLineArgument):
|
||||
|
||||
@mock.patch('magnumclient.v1.bays.BayManager.get')
|
||||
@mock.patch('magnumclient.v1.certificates.CertificateManager.get')
|
||||
def test_ca_show_success(self, mock_cert_get, mock_bay_get):
|
||||
mockbay = mock.MagicMock()
|
||||
mockbay.status = "CREATE_COMPLETE"
|
||||
mockbay.uuid = "xxx"
|
||||
mock_bay_get.return_value = mockbay
|
||||
self._test_arg_success('ca-show --bay xxx')
|
||||
expected_args = {}
|
||||
expected_args['cluster_uuid'] = mockbay.uuid
|
||||
mock_cert_get.assert_called_once_with(**expected_args)
|
||||
|
||||
@mock.patch('magnumclient.v1.clusters.ClusterManager.get')
|
||||
@mock.patch('magnumclient.v1.certificates.CertificateManager.get')
|
||||
def test_cluster_ca_show_success(self, mock_cert_get, mock_cluster_get):
|
||||
@ -45,32 +33,6 @@ class ShellTest(shell_test_base.TestCommandLineArgument):
|
||||
expected_args['cluster_uuid'] = mockcluster.uuid
|
||||
mock_cert_get.assert_called_once_with(**expected_args)
|
||||
|
||||
@mock.patch('magnumclient.v1.clusters.ClusterManager.get')
|
||||
@mock.patch('magnumclient.v1.certificates.CertificateManager.get')
|
||||
def test_positional_cluster_bay_ca_show_success(self, mock_cert_get,
|
||||
mock_cluster_get):
|
||||
mockcluster = mock.MagicMock()
|
||||
mockcluster.status = "CREATE_COMPLETE"
|
||||
mockcluster.uuid = "xxx"
|
||||
mock_cluster_get.return_value = mockcluster
|
||||
self._test_arg_success('ca-show xxx --bay not-found')
|
||||
expected_args = {}
|
||||
expected_args['cluster_uuid'] = mockcluster.uuid
|
||||
mock_cert_get.assert_called_once_with(**expected_args)
|
||||
|
||||
@mock.patch('magnumclient.v1.clusters.ClusterManager.get')
|
||||
@mock.patch('magnumclient.v1.certificates.CertificateManager.get')
|
||||
def test_cluster_bay_ca_show_success(self, mock_cert_get,
|
||||
mock_cluster_get):
|
||||
mockcluster = mock.MagicMock()
|
||||
mockcluster.status = "CREATE_COMPLETE"
|
||||
mockcluster.uuid = "xxx"
|
||||
mock_cluster_get.return_value = mockcluster
|
||||
self._test_arg_success('ca-show --cluster xxx --bay not-found')
|
||||
expected_args = {}
|
||||
expected_args['cluster_uuid'] = mockcluster.uuid
|
||||
mock_cert_get.assert_called_once_with(**expected_args)
|
||||
|
||||
@mock.patch('magnumclient.v1.clusters.ClusterManager.get')
|
||||
@mock.patch('magnumclient.v1.certificates.CertificateManager.get')
|
||||
def test_ca_show_failure_duplicate_arg(self, mock_cert_get,
|
||||
@ -82,28 +44,6 @@ class ShellTest(shell_test_base.TestCommandLineArgument):
|
||||
mock_cert_get.assert_not_called()
|
||||
mock_cluster_get.assert_not_called()
|
||||
|
||||
@mock.patch('os.path.isfile')
|
||||
@mock.patch('magnumclient.v1.bays.BayManager.get')
|
||||
@mock.patch('magnumclient.v1.certificates.CertificateManager.create')
|
||||
def test_ca_sign_success(
|
||||
self, mock_cert_create, mock_bay_get, mock_isfile):
|
||||
mock_isfile.return_value = True
|
||||
mockbay = mock.MagicMock()
|
||||
mockbay.status = "CREATE_COMPLETE"
|
||||
mockbay.uuid = "xxx"
|
||||
mock_bay_get.return_value = mockbay
|
||||
|
||||
fake_csr = 'fake-csr'
|
||||
mock_file = mock.mock_open(read_data=fake_csr)
|
||||
with mock.patch.object(certificates_shell, 'open', mock_file):
|
||||
self._test_arg_success('ca-sign '
|
||||
'--csr path/csr.pem '
|
||||
'--bay xxx')
|
||||
expected_args = {}
|
||||
expected_args['cluster_uuid'] = mockbay.uuid
|
||||
expected_args['csr'] = fake_csr
|
||||
mock_cert_create.assert_called_once_with(**expected_args)
|
||||
|
||||
@mock.patch('os.path.isfile')
|
||||
@mock.patch('magnumclient.v1.clusters.ClusterManager.get')
|
||||
@mock.patch('magnumclient.v1.certificates.CertificateManager.create')
|
||||
@ -126,26 +66,6 @@ class ShellTest(shell_test_base.TestCommandLineArgument):
|
||||
expected_args['csr'] = fake_csr
|
||||
mock_cert_create.assert_called_once_with(**expected_args)
|
||||
|
||||
@mock.patch('os.path.isfile')
|
||||
@mock.patch('magnumclient.v1.bays.BayManager.get')
|
||||
@mock.patch('magnumclient.v1.certificates.CertificateManager.create')
|
||||
def test_ca_sign_with_not_csr(
|
||||
self, mock_cert_create, mock_bay_get, mock_isfile):
|
||||
mock_isfile.return_value = False
|
||||
mockbay = mock.MagicMock()
|
||||
mockbay.status = "CREATE_COMPLETE"
|
||||
mock_bay_get.return_value = mockbay
|
||||
|
||||
fake_csr = 'fake-csr'
|
||||
mock_file = mock.mock_open(read_data=fake_csr)
|
||||
with mock.patch.object(certificates_shell, 'open', mock_file):
|
||||
self._test_arg_success('ca-sign '
|
||||
'--csr path/csr.pem '
|
||||
'--bay xxx')
|
||||
mock_isfile.assert_called_once_with('path/csr.pem')
|
||||
mock_file.assert_not_called()
|
||||
mock_cert_create.assert_not_called()
|
||||
|
||||
@mock.patch('os.path.isfile')
|
||||
@mock.patch('magnumclient.v1.clusters.ClusterManager.get')
|
||||
@mock.patch('magnumclient.v1.certificates.CertificateManager.create')
|
||||
|
@ -52,16 +52,16 @@ class BaseModelManager(base.Manager):
|
||||
|
||||
def list(self, limit=None, marker=None, sort_key=None,
|
||||
sort_dir=None, detail=False):
|
||||
"""Retrieve a list of baymodels.
|
||||
"""Retrieve a list of cluster templates.
|
||||
|
||||
:param marker: Optional, the UUID of a baymodel, eg the last
|
||||
baymodel from a previous result set. Return
|
||||
:param marker: Optional, the UUID of a template, eg the last
|
||||
template from a previous result set. Return
|
||||
the next result set.
|
||||
:param limit: The maximum number of results to return per
|
||||
request, if:
|
||||
|
||||
1) limit > 0, the maximum number of baymodels to return.
|
||||
2) limit == 0, return the entire list of baymodels.
|
||||
1) limit > 0, the maximum number of cluster templates to return.
|
||||
2) limit == 0, return the entire list of cluster templates.
|
||||
3) limit param is NOT specified (None), the number of items
|
||||
returned respect the maximum imposed by the Magnum API
|
||||
(see Magnum's api.max_limit option).
|
||||
@ -72,9 +72,9 @@ class BaseModelManager(base.Manager):
|
||||
default) or 'desc'.
|
||||
|
||||
:param detail: Optional, boolean whether to return detailed information
|
||||
about baymodels.
|
||||
about cluster templates.
|
||||
|
||||
:returns: A list of baymodels.
|
||||
:returns: A list of cluster templates.
|
||||
|
||||
"""
|
||||
if limit is not None:
|
||||
|
@ -42,16 +42,16 @@ class BaseTemplateManager(base.Manager):
|
||||
|
||||
def list(self, limit=None, marker=None, sort_key=None,
|
||||
sort_dir=None, detail=False):
|
||||
"""Retrieve a list of bays.
|
||||
"""Retrieve a list of clusters.
|
||||
|
||||
:param marker: Optional, the UUID of a bay, eg the last
|
||||
bay from a previous result set. Return
|
||||
:param marker: Optional, the UUID of a cluster, eg the last
|
||||
cluster from a previous result set. Return
|
||||
the next result set.
|
||||
:param limit: The maximum number of results to return per
|
||||
request, if:
|
||||
|
||||
1) limit > 0, the maximum number of bays to return.
|
||||
2) limit == 0, return the entire list of bays.
|
||||
1) limit > 0, the maximum number of clusters to return.
|
||||
2) limit == 0, return the entire list of clusters.
|
||||
3) limit param is NOT specified (None), the number of items
|
||||
returned respect the maximum imposed by the Magnum API
|
||||
(see Magnum's api.max_limit option).
|
||||
@ -62,9 +62,9 @@ class BaseTemplateManager(base.Manager):
|
||||
default) or 'desc'.
|
||||
|
||||
:param detail: Optional, boolean whether to return detailed information
|
||||
about bays.
|
||||
about clusters.
|
||||
|
||||
:returns: A list of bays.
|
||||
:returns: A list of clusters.
|
||||
|
||||
"""
|
||||
if limit is not None:
|
||||
|
@ -1,25 +0,0 @@
|
||||
# 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.
|
||||
|
||||
from magnumclient.v1 import basemodels
|
||||
|
||||
|
||||
CREATION_ATTRIBUTES = basemodels.CREATION_ATTRIBUTES
|
||||
|
||||
|
||||
class BayModel(basemodels.BaseModel):
|
||||
model_name = "BayModel"
|
||||
|
||||
|
||||
class BayModelManager(basemodels.BaseModelManager):
|
||||
api_name = "baymodels"
|
||||
resource_class = BayModel
|
@ -1,282 +0,0 @@
|
||||
# Copyright 2015 NEC Corporation. All rights reserved.
|
||||
#
|
||||
# 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.
|
||||
|
||||
from magnumclient.common import cliutils as utils
|
||||
from magnumclient.common import utils as magnum_utils
|
||||
from magnumclient.exceptions import InvalidAttribute
|
||||
from magnumclient.i18n import _
|
||||
from magnumclient.v1 import basemodels
|
||||
|
||||
|
||||
DEPRECATION_MESSAGE = (
|
||||
'WARNING: Baymodel commands are deprecated and will be removed in a future'
|
||||
' release.\nUse cluster commands to avoid seeing this message.')
|
||||
|
||||
|
||||
def _show_baymodel(baymodel):
|
||||
del baymodel._info['links']
|
||||
utils.print_dict(baymodel._info)
|
||||
|
||||
|
||||
@utils.arg('--name',
|
||||
metavar='<name>',
|
||||
help=_('Name of the baymodel to create.'))
|
||||
@utils.arg('--image-id',
|
||||
required=True,
|
||||
metavar='<image-id>',
|
||||
help=_('The name or UUID of the base image to customize for'
|
||||
' the bay.'))
|
||||
@utils.arg('--keypair-id',
|
||||
required=True,
|
||||
metavar='<keypair-id>',
|
||||
help=_('The name of the SSH keypair to load into the'
|
||||
' Bay nodes.'))
|
||||
@utils.arg('--external-network-id',
|
||||
required=True,
|
||||
metavar='<external-network-id>',
|
||||
help=_('The external Neutron network ID to connect to this bay'
|
||||
' model.'))
|
||||
@utils.arg('--coe',
|
||||
required=True,
|
||||
metavar='<coe>',
|
||||
help=_('Specify the Container Orchestration Engine to use.'))
|
||||
@utils.arg('--fixed-network',
|
||||
metavar='<fixed-network>',
|
||||
help=_('The private Neutron network name to connect to this bay'
|
||||
' model.'))
|
||||
@utils.arg('--fixed-subnet',
|
||||
metavar='<fixed-subnet>',
|
||||
help=_('The private Neutron subnet name to connect to bay.'))
|
||||
@utils.arg('--network-driver',
|
||||
metavar='<network-driver>',
|
||||
help=_('The network driver name for instantiating container'
|
||||
' networks.'))
|
||||
@utils.arg('--volume-driver',
|
||||
metavar='<volume-driver>',
|
||||
help=_('The volume driver name for instantiating container'
|
||||
' volume.'))
|
||||
@utils.arg('--dns-nameserver',
|
||||
metavar='<dns-nameserver>',
|
||||
default='8.8.8.8',
|
||||
help=_('The DNS nameserver to use for this baymodel.'))
|
||||
@utils.arg('--flavor-id',
|
||||
metavar='<flavor-id>',
|
||||
default='m1.medium',
|
||||
help=_('The nova flavor id to use when launching the bay.'))
|
||||
@utils.arg('--master-flavor-id',
|
||||
metavar='<master-flavor-id>',
|
||||
help=_('The nova flavor id to use when launching the master node '
|
||||
'of the bay.'))
|
||||
@utils.arg('--docker-volume-size',
|
||||
metavar='<docker-volume-size>',
|
||||
type=int,
|
||||
help=_('Specify the number of size in GB '
|
||||
'for the docker volume to use.'))
|
||||
@utils.arg('--docker-storage-driver',
|
||||
metavar='<docker-storage-driver>',
|
||||
default='devicemapper',
|
||||
help=_('Select a docker storage driver. Supported: devicemapper, '
|
||||
'overlay. Default: devicemapper'))
|
||||
@utils.arg('--http-proxy',
|
||||
metavar='<http-proxy>',
|
||||
help=_('The http_proxy address to use for nodes in bay.'))
|
||||
@utils.arg('--https-proxy',
|
||||
metavar='<https-proxy>',
|
||||
help=_('The https_proxy address to use for nodes in bay.'))
|
||||
@utils.arg('--no-proxy',
|
||||
metavar='<no-proxy>',
|
||||
help=_('The no_proxy address to use for nodes in bay.'))
|
||||
@utils.arg('--labels', metavar='<KEY1=VALUE1,KEY2=VALUE2;KEY3=VALUE3...>',
|
||||
action='append', default=[],
|
||||
help=_('Arbitrary labels in the form of key=value pairs '
|
||||
'to associate with a baymodel. '
|
||||
'May be used multiple times.'))
|
||||
@utils.arg('--tls-disabled',
|
||||
action='store_true', default=False,
|
||||
help=_('Disable TLS in the Bay.'))
|
||||
@utils.arg('--public',
|
||||
action='store_true', default=False,
|
||||
help=_('Make baymodel public.'))
|
||||
@utils.arg('--registry-enabled',
|
||||
action='store_true', default=False,
|
||||
help=_('Enable docker registry in the Bay'))
|
||||
@utils.arg('--server-type',
|
||||
metavar='<server-type>',
|
||||
default='vm',
|
||||
help=_('Specify the server type to be used '
|
||||
'for example vm. For this release '
|
||||
'default server type will be vm.'))
|
||||
@utils.arg('--master-lb-enabled',
|
||||
action='store_true', default=False,
|
||||
help=_('Indicates whether created bays should have a load balancer '
|
||||
'for master nodes or not.'))
|
||||
@utils.arg('--floating-ip-enabled',
|
||||
action='append_const',
|
||||
dest='floating_ip_enabled',
|
||||
const=True,
|
||||
default=[],
|
||||
help=_('Indicates whether created bays should have a floating ip'
|
||||
'or not.'))
|
||||
@utils.arg('--floating-ip-disabled',
|
||||
action='append_const',
|
||||
dest='floatin_ip_disabled',
|
||||
const=False,
|
||||
default=[],
|
||||
help=_('Disables floating ip creation on the new Cluster'))
|
||||
@utils.deprecated(DEPRECATION_MESSAGE)
|
||||
def do_baymodel_create(cs, args):
|
||||
"""Create a baymodel.
|
||||
|
||||
(Deprecated in favor of cluster-template-create.)
|
||||
"""
|
||||
opts = {}
|
||||
opts['name'] = args.name
|
||||
opts['flavor_id'] = args.flavor_id
|
||||
opts['master_flavor_id'] = args.master_flavor_id
|
||||
opts['image_id'] = args.image_id
|
||||
opts['keypair_id'] = args.keypair_id
|
||||
opts['external_network_id'] = args.external_network_id
|
||||
opts['fixed_network'] = args.fixed_network
|
||||
opts['fixed_subnet'] = args.fixed_subnet
|
||||
opts['network_driver'] = args.network_driver
|
||||
opts['volume_driver'] = args.volume_driver
|
||||
opts['dns_nameserver'] = args.dns_nameserver
|
||||
opts['docker_volume_size'] = args.docker_volume_size
|
||||
opts['docker_storage_driver'] = args.docker_storage_driver
|
||||
opts['coe'] = args.coe
|
||||
opts['http_proxy'] = args.http_proxy
|
||||
opts['https_proxy'] = args.https_proxy
|
||||
opts['no_proxy'] = args.no_proxy
|
||||
opts['labels'] = magnum_utils.handle_labels(args.labels)
|
||||
opts['tls_disabled'] = args.tls_disabled
|
||||
opts['public'] = args.public
|
||||
opts['registry_enabled'] = args.registry_enabled
|
||||
opts['server_type'] = args.server_type
|
||||
opts['master_lb_enabled'] = args.master_lb_enabled
|
||||
|
||||
if len(args.floating_ip_enabled) > 1:
|
||||
raise InvalidAttribute('--floating-ip-enabled and '
|
||||
'--floating-ip-disabled are '
|
||||
'mutually exclusive and '
|
||||
'should be specified only once.')
|
||||
elif len(args.floating_ip_enabled) == 1:
|
||||
opts['floating_ip_enabled'] = args.floating_ip_enabled[0]
|
||||
|
||||
baymodel = cs.baymodels.create(**opts)
|
||||
_show_baymodel(baymodel)
|
||||
|
||||
|
||||
@utils.arg('baymodels',
|
||||
metavar='<baymodels>',
|
||||
nargs='+',
|
||||
help=_('ID or name of the (baymodel)s to delete.'))
|
||||
@utils.deprecated(DEPRECATION_MESSAGE)
|
||||
def do_baymodel_delete(cs, args):
|
||||
"""Delete specified baymodel.
|
||||
|
||||
(Deprecated in favor of cluster-template-delete.)
|
||||
"""
|
||||
for baymodel in args.baymodels:
|
||||
try:
|
||||
cs.baymodels.delete(baymodel)
|
||||
print("Request to delete baymodel %s has been accepted." %
|
||||
baymodel)
|
||||
except Exception as e:
|
||||
print("Delete for baymodel %(baymodel)s failed: %(e)s" %
|
||||
{'baymodel': baymodel, 'e': e})
|
||||
|
||||
|
||||
@utils.arg('baymodel',
|
||||
metavar='<baymodel>',
|
||||
help=_('ID or name of the baymodel to show.'))
|
||||
@utils.deprecated(DEPRECATION_MESSAGE)
|
||||
def do_baymodel_show(cs, args):
|
||||
"""Show details about the given baymodel.
|
||||
|
||||
(Deprecated in favor of cluster-template-show.)
|
||||
"""
|
||||
baymodel = cs.baymodels.get(args.baymodel)
|
||||
_show_baymodel(baymodel)
|
||||
|
||||
|
||||
@utils.arg('--limit',
|
||||
metavar='<limit>',
|
||||
type=int,
|
||||
help=_('Maximum number of baymodels to return'))
|
||||
@utils.arg('--sort-key',
|
||||
metavar='<sort-key>',
|
||||
help=_('Column to sort results by'))
|
||||
@utils.arg('--sort-dir',
|
||||
metavar='<sort-dir>',
|
||||
choices=['desc', 'asc'],
|
||||
help=_('Direction to sort. "asc" or "desc".'))
|
||||
@utils.arg('--fields',
|
||||
default=None,
|
||||
metavar='<fields>',
|
||||
help=_('Comma-separated list of fields to display. '
|
||||
'Available fields: uuid, name, coe, image_id, public, link, '
|
||||
'apiserver_port, server_type, tls_disabled, registry_enabled'
|
||||
)
|
||||
)
|
||||
@utils.arg('--detail',
|
||||
action='store_true', default=False,
|
||||
help=_('Show detailed information about the baymodels.')
|
||||
)
|
||||
@utils.deprecated(DEPRECATION_MESSAGE)
|
||||
def do_baymodel_list(cs, args):
|
||||
"""Print a list of baymodels.
|
||||
|
||||
(Deprecated in favor of cluster-template-list.)
|
||||
"""
|
||||
nodes = cs.baymodels.list(limit=args.limit,
|
||||
sort_key=args.sort_key,
|
||||
sort_dir=args.sort_dir,
|
||||
detail=args.detail)
|
||||
if args.detail:
|
||||
columns = basemodels.OUTPUT_ATTRIBUTES
|
||||
else:
|
||||
columns = ['uuid', 'name']
|
||||
columns += utils._get_list_table_columns_and_formatters(
|
||||
args.fields, nodes,
|
||||
exclude_fields=(c.lower() for c in columns))[0]
|
||||
utils.print_list(nodes, columns,
|
||||
{'versions': magnum_utils.print_list_field('versions')},
|
||||
sortby_index=None)
|
||||
|
||||
|
||||
@utils.arg('baymodel', metavar='<baymodel>',
|
||||
help=_("UUID or name of baymodel"))
|
||||
@utils.arg(
|
||||
'op',
|
||||
metavar='<op>',
|
||||
choices=['add', 'replace', 'remove'],
|
||||
help=_("Operations: 'add', 'replace' or 'remove'"))
|
||||
@utils.arg(
|
||||
'attributes',
|
||||
metavar='<path=value>',
|
||||
nargs='+',
|
||||
action='append',
|
||||
default=[],
|
||||
help=_("Attributes to add/replace or remove "
|
||||
"(only PATH is necessary on remove)"))
|
||||
@utils.deprecated(DEPRECATION_MESSAGE)
|
||||
def do_baymodel_update(cs, args):
|
||||
"""Updates one or more baymodel attributes.
|
||||
|
||||
(Deprecated in favor of cluster-template-update.)
|
||||
"""
|
||||
patch = magnum_utils.args_array_to_patch(args.op, args.attributes[0])
|
||||
|
||||
baymodel = cs.baymodels.update(args.baymodel, patch)
|
||||
_show_baymodel(baymodel)
|
@ -1,29 +0,0 @@
|
||||
# Copyright 2014 NEC Corporation. All rights reserved.
|
||||
#
|
||||
# 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.
|
||||
|
||||
from magnumclient.v1 import baseunit
|
||||
|
||||
|
||||
CREATION_ATTRIBUTES = baseunit.CREATION_ATTRIBUTES
|
||||
CREATION_ATTRIBUTES.append('baymodel_id')
|
||||
CREATION_ATTRIBUTES.append('bay_create_timeout')
|
||||
|
||||
|
||||
class Bay(baseunit.BaseTemplate):
|
||||
template_name = "Bays"
|
||||
|
||||
|
||||
class BayManager(baseunit.BaseTemplateManager):
|
||||
resource_class = Bay
|
||||
template_name = 'bays'
|
@ -1,253 +0,0 @@
|
||||
# Copyright 2015 NEC Corporation. All rights reserved.
|
||||
#
|
||||
# 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.
|
||||
|
||||
from magnumclient.common import cliutils as utils
|
||||
from magnumclient.common import utils as magnum_utils
|
||||
from magnumclient import exceptions
|
||||
from magnumclient.i18n import _
|
||||
|
||||
import os
|
||||
|
||||
|
||||
DEPRECATION_MESSAGE = (
|
||||
'WARNING: Bay commands are deprecated and will be removed in a future '
|
||||
'release.\nUse cluster commands to avoid seeing this message.')
|
||||
|
||||
|
||||
def _show_bay(bay):
|
||||
del bay._info['links']
|
||||
utils.print_dict(bay._info)
|
||||
|
||||
|
||||
@utils.arg('--marker',
|
||||
metavar='<marker>',
|
||||
default=None,
|
||||
help=_('The last bay UUID of the previous page; '
|
||||
'displays list of bays after "marker".'))
|
||||
@utils.arg('--limit',
|
||||
metavar='<limit>',
|
||||
type=int,
|
||||
help=_('Maximum number of bays to return.'))
|
||||
@utils.arg('--sort-key',
|
||||
metavar='<sort-key>',
|
||||
help=_('Column to sort results by.'))
|
||||
@utils.arg('--sort-dir',
|
||||
metavar='<sort-dir>',
|
||||
choices=['desc', 'asc'],
|
||||
help=_('Direction to sort. "asc" or "desc".'))
|
||||
@utils.arg('--fields',
|
||||
default=None,
|
||||
metavar='<fields>',
|
||||
help=_('Comma-separated list of fields to display. '
|
||||
'Available fields: uuid, name, baymodel_id, stack_id, '
|
||||
'status, master_count, node_count, links, bay_create_timeout'
|
||||
)
|
||||
)
|
||||
@utils.deprecated(DEPRECATION_MESSAGE)
|
||||
def do_bay_list(cs, args):
|
||||
"""Print a list of available bays.
|
||||
|
||||
(Deprecated in favor of cluster-list.)
|
||||
"""
|
||||
bays = cs.bays.list(marker=args.marker, limit=args.limit,
|
||||
sort_key=args.sort_key,
|
||||
sort_dir=args.sort_dir)
|
||||
columns = ['uuid', 'name', 'node_count', 'master_count', 'status']
|
||||
columns += utils._get_list_table_columns_and_formatters(
|
||||
args.fields, bays,
|
||||
exclude_fields=(c.lower() for c in columns))[0]
|
||||
utils.print_list(bays, columns,
|
||||
{'versions': magnum_utils.print_list_field('versions')},
|
||||
sortby_index=None)
|
||||
|
||||
|
||||
@utils.deprecated(DEPRECATION_MESSAGE)
|
||||
@utils.arg('--name',
|
||||
metavar='<name>',
|
||||
help=_('Name of the bay to create.'))
|
||||
@utils.arg('--baymodel',
|
||||
required=True,
|
||||
metavar='<baymodel>',
|
||||
help=_('ID or name of the baymodel.'))
|
||||
@utils.arg('--node-count',
|
||||
metavar='<node-count>',
|
||||
type=int,
|
||||
default=1,
|
||||
help=_('The bay node count.'))
|
||||
@utils.arg('--master-count',
|
||||
metavar='<master-count>',
|
||||
type=int,
|
||||
default=1,
|
||||
help=_('The number of master nodes for the bay.'))
|
||||
@utils.arg('--discovery-url',
|
||||
metavar='<discovery-url>',
|
||||
help=_('Specifies custom discovery url for node discovery.'))
|
||||
@utils.arg('--timeout',
|
||||
metavar='<timeout>',
|
||||
type=int,
|
||||
default=60,
|
||||
help=_('The timeout for bay creation in minutes. The default '
|
||||
'is 60 minutes.'))
|
||||
def do_bay_create(cs, args):
|
||||
"""Create a bay.
|
||||
|
||||
(Deprecated in favor of cluster-create.)
|
||||
"""
|
||||
baymodel = cs.baymodels.get(args.baymodel)
|
||||
|
||||
opts = {}
|
||||
opts['name'] = args.name
|
||||
opts['baymodel_id'] = baymodel.uuid
|
||||
opts['node_count'] = args.node_count
|
||||
opts['master_count'] = args.master_count
|
||||
opts['discovery_url'] = args.discovery_url
|
||||
opts['bay_create_timeout'] = args.timeout
|
||||
try:
|
||||
bay = cs.bays.create(**opts)
|
||||
# support for non-async in 1.1
|
||||
if args.magnum_api_version and args.magnum_api_version == '1.1':
|
||||
_show_bay(bay)
|
||||
else:
|
||||
uuid = str(bay._info['uuid'])
|
||||
print("Request to create bay %s has been accepted." % uuid)
|
||||
except Exception as e:
|
||||
print("Create for bay %s failed: %s" %
|
||||
(opts['name'], e))
|
||||
|
||||
|
||||
@utils.arg('bay',
|
||||
metavar='<bay>',
|
||||
nargs='+',
|
||||
help=_('ID or name of the (bay)s to delete.'))
|
||||
@utils.deprecated(DEPRECATION_MESSAGE)
|
||||
def do_bay_delete(cs, args):
|
||||
"""Delete specified bay.
|
||||
|
||||
(Deprecated in favor of cluster-delete.)
|
||||
"""
|
||||
for id in args.bay:
|
||||
try:
|
||||
cs.bays.delete(id)
|
||||
print("Request to delete bay %s has been accepted." %
|
||||
id)
|
||||
except Exception as e:
|
||||
print("Delete for bay %(bay)s failed: %(e)s" %
|
||||
{'bay': id, 'e': e})
|
||||
|
||||
|
||||
@utils.arg('bay',
|
||||
metavar='<bay>',
|
||||
help=_('ID or name of the bay to show.'))
|
||||
@utils.arg('--long',
|
||||
action='store_true', default=False,
|
||||
help=_('Display extra associated Baymodel info.'))
|
||||
@utils.deprecated(DEPRECATION_MESSAGE)
|
||||
def do_bay_show(cs, args):
|
||||
"""Show details about the given bay.
|
||||
|
||||
(Deprecated in favor of cluster-show.)
|
||||
"""
|
||||
bay = cs.bays.get(args.bay)
|
||||
if args.long:
|
||||
baymodel = cs.baymodels.get(bay.baymodel_id)
|
||||
del baymodel._info['links'], baymodel._info['uuid']
|
||||
|
||||
for key in baymodel._info:
|
||||
if 'baymodel_' + key not in bay._info:
|
||||
bay._info['baymodel_' + key] = baymodel._info[key]
|
||||
_show_bay(bay)
|
||||
|
||||
|
||||
@utils.arg('bay', metavar='<bay>', help=_("UUID or name of bay"))
|
||||
@utils.arg('--rollback',
|
||||
action='store_true', default=False,
|
||||
help=_('Rollback bay on update failure.'))
|
||||
@utils.arg(
|
||||
'op',
|
||||
metavar='<op>',
|
||||
choices=['add', 'replace', 'remove'],
|
||||
help=_("Operations: 'add', 'replace' or 'remove'"))
|
||||
@utils.arg(
|
||||
'attributes',
|
||||
metavar='<path=value>',
|
||||
nargs='+',
|
||||
action='append',
|
||||
default=[],
|
||||
help=_("Attributes to add/replace or remove "
|
||||
"(only PATH is necessary on remove)"))
|
||||
@utils.deprecated(DEPRECATION_MESSAGE)
|
||||
def do_bay_update(cs, args):
|
||||
"""Update information about the given bay.
|
||||
|
||||
(Deprecated in favor of cluster-update.)
|
||||
"""
|
||||
if args.rollback and args.magnum_api_version and \
|
||||
args.magnum_api_version in ('1.0', '1.1', '1.2'):
|
||||
raise exceptions.CommandError(
|
||||
"Rollback is not supported in API v%s. "
|
||||
"Please use API v1.3+." % args.magnum_api_version)
|
||||
patch = magnum_utils.args_array_to_patch(args.op, args.attributes[0])
|
||||
bay = cs.bays.update(args.bay, patch, args.rollback)
|
||||
if args.magnum_api_version and args.magnum_api_version == '1.1':
|
||||
_show_bay(bay)
|
||||
else:
|
||||
print("Request to update bay %s has been accepted." % args.bay)
|
||||
|
||||
|
||||
@utils.arg('bay',
|
||||
metavar='<bay>',
|
||||
help=_('ID or name of the bay to retrieve config.'))
|
||||
@utils.arg('--dir',
|
||||
metavar='<dir>',
|
||||
default='.',
|
||||
help=_('Directory to save the certificate and config files.'))
|
||||
@utils.arg('--force',
|
||||
action='store_true', default=False,
|
||||
help=_('Overwrite files if existing.'))
|
||||
@utils.deprecated(DEPRECATION_MESSAGE)
|
||||
def do_bay_config(cs, args):
|
||||
"""Configure native client to access bay.
|
||||
|
||||
You can source the output of this command to get the native client of the
|
||||
corresponding COE configured to access the bay.
|
||||
|
||||
Example: eval $(magnum bay-config <bay-name>).
|
||||
|
||||
(Deprecated in favor of cluster-config.)
|
||||
"""
|
||||
args.dir = os.path.abspath(args.dir)
|
||||
bay = cs.bays.get(args.bay)
|
||||
if (hasattr(bay, 'api_address') and bay.api_address is None):
|
||||
print("WARNING: The bay's api_address is not known yet.")
|
||||
baymodel = cs.baymodels.get(bay.baymodel_id)
|
||||
opts = {
|
||||
'cluster_uuid': bay.uuid,
|
||||
}
|
||||
|
||||
if not baymodel.tls_disabled:
|
||||
tls = magnum_utils.generate_csr_and_key()
|
||||
tls['ca'] = cs.certificates.get(**opts).pem
|
||||
opts['csr'] = tls['csr']
|
||||
tls['cert'] = cs.certificates.create(**opts).pem
|
||||
for k in ('key', 'cert', 'ca'):
|
||||
fname = "%s/%s.pem" % (args.dir, k)
|
||||
if os.path.exists(fname) and not args.force:
|
||||
raise Exception("File %s exists, aborting." % fname)
|
||||
else:
|
||||
f = open(fname, "w")
|
||||
f.write(tls[k])
|
||||
f.close()
|
||||
|
||||
print(magnum_utils.config_cluster(bay, baymodel, cfg_dir=args.dir,
|
||||
force=args.force))
|
@ -42,8 +42,6 @@ class CertificateManager(base.Manager):
|
||||
for (key, value) in kwargs.items():
|
||||
if key in CREATION_ATTRIBUTES:
|
||||
new[key] = value
|
||||
elif key == 'bay_uuid':
|
||||
new['cluster_uuid'] = value
|
||||
else:
|
||||
raise exceptions.InvalidAttribute(
|
||||
"Key must be in %s" % ",".join(CREATION_ATTRIBUTES))
|
||||
|
@ -18,11 +18,6 @@ from magnumclient.common import cliutils as utils
|
||||
from magnumclient.i18n import _
|
||||
|
||||
|
||||
DEPRECATION_MESSAGE = (
|
||||
'WARNING: The bay parameter is deprecated and will be removed in a future '
|
||||
'release.\nUse the cluster parameter to avoid seeing this message.')
|
||||
|
||||
|
||||
def _show_cert(certificate):
|
||||
print(certificate.pem)
|
||||
|
||||
@ -31,18 +26,11 @@ def _get_target_uuid(cs, args):
|
||||
target = None
|
||||
if args.cluster:
|
||||
target = cs.clusters.get(args.cluster)
|
||||
elif args.bay:
|
||||
print(DEPRECATION_MESSAGE)
|
||||
target = cs.bays.get(args.bay)
|
||||
else:
|
||||
raise utils.MissingArgs(['--cluster or --bay'])
|
||||
raise utils.MissingArgs(['--cluster'])
|
||||
return target.uuid
|
||||
|
||||
|
||||
@utils.arg('--bay',
|
||||
required=False,
|
||||
metavar='<bay>',
|
||||
help=_('ID or name of the bay.'))
|
||||
@utils.arg('postional_cluster',
|
||||
metavar='<cluster>',
|
||||
nargs='?',
|
||||
@ -55,7 +43,7 @@ def _get_target_uuid(cs, args):
|
||||
utils.CLUSTER_DEPRECATION_HELP))
|
||||
@utils.deprecated(utils.MAGNUM_CLIENT_DEPRECATION_WARNING)
|
||||
def do_ca_show(cs, args):
|
||||
"""Show details about the CA certificate for a bay or cluster."""
|
||||
"""Show details about the CA certificate for a cluster."""
|
||||
utils.validate_cluster_args(args.postional_cluster, args.cluster)
|
||||
args.cluster = args.postional_cluster or args.cluster
|
||||
opts = {
|
||||
@ -70,17 +58,13 @@ def do_ca_show(cs, args):
|
||||
metavar='<csr>',
|
||||
help=_('File path of the csr file to send to Magnum'
|
||||
' to get signed.'))
|
||||
@utils.arg('--bay',
|
||||
required=False,
|
||||
metavar='<bay>',
|
||||
help=_('ID or name of the bay.'))
|
||||
@utils.arg('--cluster',
|
||||
required=False,
|
||||
metavar='<cluster>',
|
||||
help=_('ID or name of the cluster.'))
|
||||
@utils.deprecated(utils.MAGNUM_CLIENT_DEPRECATION_WARNING)
|
||||
def do_ca_sign(cs, args):
|
||||
"""Generate the CA certificate for a bay or cluster."""
|
||||
"""Generate the CA certificate for a cluster."""
|
||||
opts = {
|
||||
'cluster_uuid': _get_target_uuid(cs, args)
|
||||
}
|
||||
@ -102,7 +86,7 @@ def do_ca_sign(cs, args):
|
||||
help=_('ID or name of the cluster.'))
|
||||
@utils.deprecated(utils.MAGNUM_CLIENT_DEPRECATION_WARNING)
|
||||
def do_ca_rotate(cs, args):
|
||||
"""Rotate the CA certificate for a bay or cluster to revoke access."""
|
||||
"""Rotate the CA certificate for a cluster to revoke access."""
|
||||
cluster = cs.clusters.get(args.cluster)
|
||||
opts = {
|
||||
'cluster_uuid': cluster.uuid
|
||||
|
@ -19,8 +19,6 @@ import os_client_config
|
||||
from oslo_utils import importutils
|
||||
|
||||
from magnumclient.common import httpclient
|
||||
from magnumclient.v1 import baymodels
|
||||
from magnumclient.v1 import bays
|
||||
from magnumclient.v1 import certificates
|
||||
from magnumclient.v1 import cluster_templates
|
||||
from magnumclient.v1 import clusters
|
||||
@ -197,10 +195,8 @@ class Client(object):
|
||||
**kwargs
|
||||
)
|
||||
|
||||
self.bays = bays.BayManager(self.http_client)
|
||||
self.clusters = clusters.ClusterManager(self.http_client)
|
||||
self.certificates = certificates.CertificateManager(self.http_client)
|
||||
self.baymodels = baymodels.BayModelManager(self.http_client)
|
||||
self.cluster_templates = \
|
||||
cluster_templates.ClusterTemplateManager(self.http_client)
|
||||
self.mservices = mservices.MServiceManager(self.http_client)
|
||||
|
@ -13,8 +13,6 @@
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
|
||||
from magnumclient.v1 import baymodels_shell
|
||||
from magnumclient.v1 import bays_shell
|
||||
from magnumclient.v1 import certificates_shell
|
||||
from magnumclient.v1 import cluster_templates_shell
|
||||
from magnumclient.v1 import clusters_shell
|
||||
@ -23,8 +21,6 @@ from magnumclient.v1 import quotas_shell
|
||||
from magnumclient.v1 import stats_shell
|
||||
|
||||
COMMAND_MODULES = [
|
||||
baymodels_shell,
|
||||
bays_shell,
|
||||
certificates_shell,
|
||||
clusters_shell,
|
||||
cluster_templates_shell,
|
||||
|
@ -0,0 +1,4 @@
|
||||
---
|
||||
deprecations:
|
||||
- |
|
||||
Remove support for bays and baymodels.
|
Loading…
Reference in New Issue
Block a user