Merge "Nodegroup can be created not only for GRE"
This commit is contained in:
@@ -12,12 +12,17 @@
|
||||
# License for the specific language governing permissions and limitations
|
||||
# under the License.
|
||||
|
||||
import sys
|
||||
|
||||
import six
|
||||
|
||||
from fuelclient.cli.actions.base import Action
|
||||
from fuelclient.cli.actions.base import check_all
|
||||
import fuelclient.cli.arguments as Args
|
||||
from fuelclient.cli.arguments import group
|
||||
from fuelclient.cli.error import ActionException
|
||||
from fuelclient.cli.formatting import format_table
|
||||
from fuelclient.objects import Environment
|
||||
from fuelclient.objects.nodegroup import NodeGroup
|
||||
from fuelclient.objects.nodegroup import NodeGroupCollection
|
||||
|
||||
@@ -57,7 +62,20 @@ class NodeGroupAction(Action):
|
||||
"""Create a new node group
|
||||
fuel --env 1 nodegroup --create --name "group 1"
|
||||
"""
|
||||
NodeGroup.create(params.name, int(params.env))
|
||||
env_id = int(params.env)
|
||||
NodeGroup.create(params.name, env_id)
|
||||
env = Environment(env_id)
|
||||
network_data = env.get_network_data()
|
||||
seg_type = network_data['networking_parameters'].get(
|
||||
'segmentation_type'
|
||||
)
|
||||
if seg_type == 'vlan':
|
||||
six.print_("WARNING: In VLAN segmentation type, there will be no "
|
||||
"connectivity over private network between instances "
|
||||
"running on hypervisors in different segments and that "
|
||||
"it's a user's responsibility to handle this "
|
||||
"situation.",
|
||||
file=sys.stderr)
|
||||
|
||||
def delete(self, params):
|
||||
"""Delete the specified node groups
|
||||
|
||||
@@ -239,6 +239,24 @@ class TestHandlers(base.BaseTestCase):
|
||||
msg
|
||||
)
|
||||
|
||||
def test_node_group_creation_prints_warning_w_seg_type_vlan(self):
|
||||
warn_msg = ("WARNING: In VLAN segmentation type, there will be no "
|
||||
"connectivity over private network between instances "
|
||||
"running on hypervisors in different segments and that "
|
||||
"it's a user's responsibility to handle this "
|
||||
"situation.")
|
||||
|
||||
self.load_data_to_nailgun_server()
|
||||
self.run_cli_commands((
|
||||
"env create --name=NewEnv --release=2 --nst=vlan",
|
||||
|
||||
))
|
||||
self.check_for_stderr(
|
||||
"nodegroup create --name tor1 --env 1",
|
||||
warn_msg,
|
||||
check_errors=False
|
||||
)
|
||||
|
||||
def test_create_network_group_fails_w_duplicate_name(self):
|
||||
err_msg = ("(Network with name storage already exists "
|
||||
"in node group default)\n")
|
||||
|
||||
@@ -13,35 +13,50 @@
|
||||
# under the License.
|
||||
|
||||
import mock
|
||||
import requests_mock
|
||||
|
||||
from fuelclient.tests import base
|
||||
|
||||
|
||||
@mock.patch('fuelclient.client.requests')
|
||||
@requests_mock.mock()
|
||||
class TestNodeGroupActions(base.UnitTestCase):
|
||||
|
||||
def setUp(self):
|
||||
super(TestNodeGroupActions, self).setUp()
|
||||
|
||||
self.env_id = 42
|
||||
self.req_base_path = '/api/v1/nodegroups/'
|
||||
|
||||
def test_list_nodegroups(self, mreq):
|
||||
mreq.get(self.req_base_path)
|
||||
self.execute(['fuel', 'nodegroup', '--list'])
|
||||
call_args = mreq.get.call_args_list[-1]
|
||||
url = call_args[0][0]
|
||||
self.assertIn('nodegroups/', url)
|
||||
self.assertEqual(mreq.last_request.method, 'GET')
|
||||
self.assertEqual(mreq.last_request.path, self.req_base_path)
|
||||
|
||||
def test_create_nodegroup(self, mreq):
|
||||
mreq.post(self.req_base_path)
|
||||
self.execute(['fuel', 'nodegroup', '--create',
|
||||
'--name', 'test group', '--env', '1'])
|
||||
'--name', 'test group', '--env', str(self.env_id)])
|
||||
|
||||
call_args = mreq.post.call_args_list[0]
|
||||
call_data = call_args[-1]['data']
|
||||
url = call_args[0][0]
|
||||
self.assertIn('"cluster_id": 1', call_data)
|
||||
self.assertIn('"name": "test group"', call_data)
|
||||
self.assertIn('nodegroups/', url)
|
||||
call_data = mreq.last_request.json()
|
||||
self.assertEqual(self.env_id, call_data['cluster_id'])
|
||||
self.assertEqual('test group', call_data['name'])
|
||||
|
||||
self.assertEqual(mreq.last_request.method, 'POST')
|
||||
self.assertEqual(mreq.last_request.path, self.req_base_path)
|
||||
|
||||
def test_delete_nodegroup(self, mreq):
|
||||
self.execute(['fuel', 'nodegroup', '--delete', '--group', '3'])
|
||||
call_args = mreq.delete.call_args_list[-1]
|
||||
url = call_args[0][0]
|
||||
self.assertIn('nodegroups/3', url)
|
||||
path = self.req_base_path + str(self.env_id) + '/'
|
||||
mreq.get(path, json={'name': 'test group'})
|
||||
delete_path = self.req_base_path + str(self.env_id) + '/'
|
||||
mreq.delete(delete_path)
|
||||
self.execute(['fuel', 'nodegroup', '--delete', '--group',
|
||||
str(self.env_id)])
|
||||
self.assertEqual(mreq.request_history[-2].method, 'GET')
|
||||
self.assertEqual(mreq.request_history[-2].path, path)
|
||||
|
||||
self.assertEqual(mreq.last_request.method, 'DELETE')
|
||||
self.assertEqual(mreq.last_request.path, delete_path)
|
||||
|
||||
def test_assign_nodegroup_fails_w_multiple_groups(self, mreq):
|
||||
err_msg = "Nodes can only be assigned to one node group.\n"
|
||||
@@ -54,7 +69,7 @@ class TestNodeGroupActions(base.UnitTestCase):
|
||||
self.assertEqual(msg, err_msg)
|
||||
|
||||
@mock.patch('fuelclient.objects.nodegroup.NodeGroup.assign')
|
||||
def test_assign_nodegroup(self, m_assign, mreq):
|
||||
def test_assign_nodegroup(self, m_req, m_assign):
|
||||
self.execute(['fuel', 'nodegroup', '--assign', '--node', '1',
|
||||
'--env', '1', '--group', '2'])
|
||||
m_assign.assert_called_with([1])
|
||||
|
||||
Reference in New Issue
Block a user