Browse Source

Adding Rabbit Authentication support

implements: blueprint custom-default-user

Change-Id: I405df9b5efa85826ee7f39bd54b3305a15518cd5
tags/0.9.0^2
dagnello 4 years ago
parent
commit
e21e462fe4
4 changed files with 182 additions and 6 deletions
  1. +2
    -1
      cueclient/tests/base.py
  2. +151
    -2
      cueclient/tests/unit/v1/test_clusters.py
  3. +21
    -1
      cueclient/v1/cli/clusters.py
  4. +8
    -2
      cueclient/v1/clusters.py

+ 2
- 1
cueclient/tests/base.py View File

@@ -50,7 +50,8 @@ class TestCueBase(testtools.TestCase):
def execute(self, cmd_class, arglist, verifylist):
cmd = cmd_class(self.app, argparse.Namespace())
parsed_args = self.check_parser(cmd, arglist, verifylist)
return cmd.take_action(parsed_args)
data = cmd.take_action(parsed_args)
return data

def assert_called(self, method, path, body=None):
self.assertEqual(self.requests.last_request.method, method)

+ 151
- 2
cueclient/tests/unit/v1/test_clusters.py View File

@@ -71,6 +71,7 @@ class TestCreateCluster(base.TestCueBase):
cluster_network_id = "9d6708ee-ea48-4e78-bef6-b50b48405091"
cluster_flavor = "1"
cluster_size = "2"
auth = "type=plain,user=rabbitmq,pass=rabbit"

def test_create_cluster(self):
arglist = ["--name", self.cluster_name,
@@ -84,8 +85,156 @@ class TestCreateCluster(base.TestCueBase):
('size', self.cluster_size)
]

request_body = {'name': self.cluster_name,
'network_id': [self.cluster_network_id],
'flavor': self.cluster_flavor,
'size': self.cluster_size,
'volume_size': None,
'authentication': {'type': 'plain',
'token': {'username': None,
'password': None}}}

self.execute(clusters.CreateClusterCommand, arglist, verifylist)
self.assert_called('POST', '/clusters', request_body)

def test_create_cluster_rabbit_auth(self):
arglist = ["--name", self.cluster_name,
"--nic", self.cluster_network_id,
"--flavor", self.cluster_flavor,
"--size", self.cluster_size,
"--auth", self.auth,
]
verifylist = [
('name', self.cluster_name),
('nic', self.cluster_network_id),
('flavor', self.cluster_flavor),
('size', self.cluster_size),
('auth', self.auth),
]

request_body = {'name': self.cluster_name,
'network_id': [self.cluster_network_id],
'flavor': self.cluster_flavor,
'size': self.cluster_size,
'volume_size': None,
'authentication': {'type': 'plain',
'token': {'username': 'rabbitmq',
'password': 'rabbit'}}}

self.execute(clusters.CreateClusterCommand, arglist, verifylist)
self.assert_called('POST', '/clusters', request_body)

def test_create_cluster_rabbit_auth_type_missing(self):

arglist = ["--name", self.cluster_name,
"--nic", self.cluster_network_id,
"--flavor", self.cluster_flavor,
"--size", self.cluster_size,
"--auth", "user=rabbitmq,pass=rabbit",
]
verifylist = [
('name', self.cluster_name),
('nic', self.cluster_network_id),
('flavor', self.cluster_flavor),
('size', self.cluster_size),
('auth', "user=rabbitmq,pass=rabbit"),
]

request_body = {'name': self.cluster_name,
'network_id': [self.cluster_network_id],
'flavor': self.cluster_flavor,
'size': self.cluster_size,
'volume_size': None,
'authentication': {'type': 'plain',
'token': {'username': 'rabbitmq',
'password': 'rabbit'}}}

self.execute(clusters.CreateClusterCommand, arglist, verifylist)
self.assert_called('POST', '/clusters', request_body)

def test_create_cluster_rabbit_auth_type_empty(self):

arglist = ["--name", self.cluster_name,
"--nic", self.cluster_network_id,
"--flavor", self.cluster_flavor,
"--size", self.cluster_size,
"--auth", "type=,user=rabbitmq,pass=rabbit",
]
verifylist = [
('name', self.cluster_name),
('nic', self.cluster_network_id),
('flavor', self.cluster_flavor),
('size', self.cluster_size),
('auth', "type=,user=rabbitmq,pass=rabbit"),
]

request_body = {'name': self.cluster_name,
'network_id': [self.cluster_network_id],
'flavor': self.cluster_flavor,
'size': self.cluster_size,
'volume_size': None,
'authentication': {'type': 'plain',
'token': {'username': 'rabbitmq',
'password': 'rabbit'}}}

self.execute(clusters.CreateClusterCommand, arglist, verifylist)
self.assert_called('POST', '/clusters', request_body)

def test_create_cluster_rabbit_auth_user_missing(self):

arglist = ["--name", self.cluster_name,
"--nic", self.cluster_network_id,
"--flavor", self.cluster_flavor,
"--size", self.cluster_size,
"--auth", "type=plain,pass=rabbit",
]
verifylist = [
('name', self.cluster_name),
('nic', self.cluster_network_id),
('flavor', self.cluster_flavor),
('size', self.cluster_size),
('auth', "type=plain,pass=rabbit"),
]

request_body = {'name': self.cluster_name,
'network_id': [self.cluster_network_id],
'flavor': self.cluster_flavor,
'size': self.cluster_size,
'volume_size': None,
'authentication': {'type': 'plain',
'token': {'username': None,
'password': 'rabbit'}}}

self.execute(clusters.CreateClusterCommand, arglist, verifylist)
self.assert_called('POST', '/clusters', request_body)

def test_create_cluster_rabbit_auth_password_missing(self):

arglist = ["--name", self.cluster_name,
"--nic", self.cluster_network_id,
"--flavor", self.cluster_flavor,
"--size", self.cluster_size,
"--auth", "type=plain,user=rabbitmq",
]
verifylist = [
('name', self.cluster_name),
('nic', self.cluster_network_id),
('flavor', self.cluster_flavor),
('size', self.cluster_size),
('auth', "type=plain,user=rabbitmq"),
]

request_body = {'name': self.cluster_name,
'network_id': [self.cluster_network_id],
'flavor': self.cluster_flavor,
'size': self.cluster_size,
'volume_size': None,
'authentication': {'type': 'plain',
'token': {'username': 'rabbitmq',
'password': None}}}

self.execute(clusters.CreateClusterCommand, arglist, verifylist)
self.assert_called('POST', '/clusters')
self.assert_called('POST', '/clusters', request_body)

def test_create_cluster_without_name(self):
"""test create cluster without 'name' argument."""
@@ -145,4 +294,4 @@ class TestDeleteCluster(base.TestCueBase):
result = self.execute(clusters.DeleteClusterCommand, arglist,
verifylist)
self.assert_called('DELETE', '/clusters/' + cluster_id)
self.assertEqual(None, result)
self.assertEqual(None, result)

+ 21
- 1
cueclient/v1/cli/clusters.py View File

@@ -73,19 +73,39 @@ class CreateClusterCommand(show.ShowOne):
required=True)
parser.add_argument('--flavor', help="Flavor to use.", required=True)
parser.add_argument('--size', help="Number of nodes", required=True)

parser.add_argument('--volume_size', help="Volume size")
parser.add_argument('--auth',
metavar="<type=type,user=user,pass=pass>",
help="broker authentication,"
"type=type,user=user,pass=pass")

return parser

def take_action(self, parsed_args):
client = self.app.client_manager.mb

auth_type = username = password = None
if parsed_args.auth:
for kv_str in parsed_args.auth.split(","):
k, v = kv_str.split("=")
if 'type' == k:
auth_type = v
elif 'user' == k:
username = v
elif 'pass' == k:
password = v
if not auth_type:
auth_type = 'plain'
data = client.clusters.create(
name=parsed_args.name,
nic=parsed_args.nic,
flavor=parsed_args.flavor,
size=parsed_args.size,
volume_size=parsed_args.volume_size)
volume_size=parsed_args.volume_size,
auth_type=auth_type,
username=username,
password=password)

return zip(*sorted(six.iteritems(data)))


+ 8
- 2
cueclient/v1/clusters.py View File

@@ -22,14 +22,20 @@ Cluster = warlock.model_factory(utils.load_schema('v1', 'cluster'))

class ClusterController(controller.Controller):
"""Cluster Controller to manages operations."""
def create(self, name, nic, flavor, size, volume_size):
def create(self, name, nic, flavor, size, volume_size, auth_type, username,
password):
"""Create Cluster"""
auth = {'type': auth_type,
'token': {'username': username,
'password': password}}

data = {
"network_id": nic.split(","),
"name": name,
"flavor": flavor,
"size": size,
"volume_size": volume_size
"volume_size": volume_size,
"authentication": auth,
}
url = self.build_url("/clusters")


Loading…
Cancel
Save