[MGM]: Modify pool manager to support new Nova installations
Change-Id: I6e30fdd24d978bc638aba58b98a8cea7319aa39f
This commit is contained in:
@@ -96,7 +96,7 @@ class BuildController(object):
|
||||
status = status['server']
|
||||
if status['status'] == 'ACTIVE':
|
||||
self.msg['name'] = status['name']
|
||||
addresses = status['addresses']['private']
|
||||
addresses = status['addresses'].itervalues().next()
|
||||
for address in addresses:
|
||||
if not address['addr'].startswith('10.'):
|
||||
break
|
||||
|
||||
@@ -46,7 +46,7 @@ def main():
|
||||
options = Options('mgm', 'Node Management Daemon')
|
||||
options.parser.add_argument(
|
||||
'--az', type=int,
|
||||
help='The az number the node will reside in (to be passed to the API'
|
||||
help='The az the nodes and IPs will reside in (to be passed to the API'
|
||||
' server)'
|
||||
)
|
||||
options.parser.add_argument(
|
||||
@@ -71,7 +71,11 @@ def main():
|
||||
)
|
||||
options.parser.add_argument(
|
||||
'--nova_tenant',
|
||||
help='the tenant for the Nova API'
|
||||
help='the tenant name for the Nova API'
|
||||
)
|
||||
options.parser.add_argument(
|
||||
'--nova_tenant_id',
|
||||
help='the tenant ID for the Nova API'
|
||||
)
|
||||
options.parser.add_argument(
|
||||
'--nova_keyname',
|
||||
@@ -91,6 +95,18 @@ def main():
|
||||
help='the image size ID (flavor ID) or name to use for new nodes spun'
|
||||
' up in the Nova API'
|
||||
)
|
||||
options.parser.add_argument(
|
||||
'--nova_az_name',
|
||||
help='the az name to build in'
|
||||
)
|
||||
options.parser.add_argument(
|
||||
'--nova_insecure', action='store_true',
|
||||
help='do not attempt to verify Nova/Keystone SSL certificates'
|
||||
)
|
||||
options.parser.add_argument(
|
||||
'--nova_bypass_url',
|
||||
help='use a different URL to the one supplied by the service'
|
||||
)
|
||||
options.parser.add_argument(
|
||||
'--gearman', action='append', metavar='HOST:PORT', default=[],
|
||||
help='Gearman job servers'
|
||||
@@ -118,7 +134,7 @@ def main():
|
||||
required_args = [
|
||||
'az',
|
||||
'nova_image', 'nova_image_size', 'nova_secgroup', 'nova_keyname',
|
||||
'nova_tenant', 'nova_region', 'nova_user', 'nova_pass', 'nova_auth_url'
|
||||
'nova_region', 'nova_user', 'nova_pass', 'nova_auth_url'
|
||||
]
|
||||
|
||||
# NOTE(LinuxJedi): We are checking for required args here because the
|
||||
|
||||
@@ -43,19 +43,20 @@ class Node(object):
|
||||
args.nova_auth_url,
|
||||
region_name=args.nova_region,
|
||||
no_cache=True,
|
||||
insecure=args.nova_insecure,
|
||||
tenant_id=args.nova_tenant_id,
|
||||
bypass_url=args.nova_bypass_url,
|
||||
service_type='compute'
|
||||
)
|
||||
self.keyname = args.nova_keyname
|
||||
self.secgroup = args.nova_secgroup
|
||||
self.node_basename = args.node_basename
|
||||
self.az = args.nova_az_name
|
||||
# Replace '_' with '-' in basename
|
||||
if self.node_basename:
|
||||
self.node_basename = self.node_basename.replace('_', '-')
|
||||
|
||||
if args.nova_image.isdigit():
|
||||
self.image = args.nova_image
|
||||
else:
|
||||
self.image = self._get_image(args.nova_image)
|
||||
self.image = args.nova_image
|
||||
|
||||
if args.nova_image_size.isdigit():
|
||||
self.node_type = args.nova_image_size
|
||||
@@ -142,6 +143,7 @@ class Node(object):
|
||||
"flavorRef": self.node_type,
|
||||
"max_count": 1,
|
||||
"min_count": 1,
|
||||
"availability_zone": self.az,
|
||||
"networks": [],
|
||||
"security_groups": [{"name": self.secgroup}]
|
||||
}}
|
||||
|
||||
@@ -1,98 +0,0 @@
|
||||
import logging
|
||||
import mock
|
||||
import os
|
||||
import requests
|
||||
import testtools
|
||||
|
||||
import mock_objects
|
||||
from libra.mgm.nova import Node, BuildError
|
||||
|
||||
fake_body = open(
|
||||
os.path.join(os.path.dirname(__file__), "fake_body.json"), 'r').read()
|
||||
|
||||
|
||||
class Args(object):
|
||||
nova_user = "password"
|
||||
nova_pass = "auth_test"
|
||||
nova_tenant = "tenant1"
|
||||
nova_region = "region1"
|
||||
nova_keyname = "default"
|
||||
nova_secgroup = "default"
|
||||
nova_image = '1234'
|
||||
nova_image_size = '100'
|
||||
nova_auth_url = ''
|
||||
node_basename = ''
|
||||
|
||||
|
||||
class TestResponse(requests.Response):
|
||||
"""
|
||||
Class used to wrap requests.Response and provide some
|
||||
convenience to initialize with a dict
|
||||
"""
|
||||
|
||||
def __init__(self, data):
|
||||
self._text = None
|
||||
super(TestResponse, self)
|
||||
if isinstance(data, dict):
|
||||
self.status_code = data.get('status', None)
|
||||
self.headers = data.get('headers', None)
|
||||
# Fake the text attribute to streamline Response creation
|
||||
self._text = data.get('text', None)
|
||||
else:
|
||||
self.status_code = data
|
||||
|
||||
def __eq__(self, other):
|
||||
return self.__dict__ == other.__dict__
|
||||
|
||||
@property
|
||||
def text(self):
|
||||
return self._text
|
||||
|
||||
|
||||
fake_response = TestResponse({"status": 200, "text": fake_body})
|
||||
fake_bad_response = TestResponse({"status": 500, "text": ""})
|
||||
fake_del_response = TestResponse({"status": 204, "text": ""})
|
||||
mock_request = mock.Mock(return_value=(fake_response))
|
||||
mock_bad_request = mock.Mock(return_value=(fake_bad_response))
|
||||
mock_del_request = mock.Mock(return_value=(fake_del_response))
|
||||
|
||||
|
||||
class TestLBaaSMgmTask(testtools.TestCase):
|
||||
def setUp(self):
|
||||
super(TestLBaaSMgmTask, self).setUp()
|
||||
self.logger = logging.getLogger('lbass_mgm_test')
|
||||
self.lh = mock_objects.MockLoggingHandler()
|
||||
self.logger.setLevel(logging.DEBUG)
|
||||
self.logger.addHandler(self.lh)
|
||||
|
||||
|
||||
class TestLBaaSMgmNova(testtools.TestCase):
|
||||
def setUp(self):
|
||||
super(TestLBaaSMgmNova, self).setUp()
|
||||
args = Args()
|
||||
self.api = Node(args)
|
||||
self.api.nova.management_url = "http://example.com"
|
||||
self.api.nova.auth_token = "token"
|
||||
|
||||
def testCreateNode(self):
|
||||
with mock.patch.object(requests, "request", mock_request):
|
||||
with mock.patch('time.time', mock.Mock(return_value=1234)):
|
||||
data = self.api.build()
|
||||
self.assertEqual(data, 417773)
|
||||
|
||||
def testCreateNodeFail(self):
|
||||
with mock.patch.object(requests, "request", mock_bad_request):
|
||||
with mock.patch('time.time', mock.Mock(return_value=1234)):
|
||||
self.assertRaises(BuildError, self.api.build)
|
||||
|
||||
def testDeleteNodeFail(self):
|
||||
with mock.patch.object(requests, "request", mock_bad_request):
|
||||
with mock.patch('time.time', mock.Mock(return_value=1234)):
|
||||
resp, data = self.api.delete('1234')
|
||||
self.assertFalse(resp)
|
||||
|
||||
def testDeleteNodeSucceed(self):
|
||||
with mock.patch.object(requests, "request", mock_del_request):
|
||||
with mock.patch('time.time', mock.Mock(return_value=1234)):
|
||||
resp, data = self.api.delete('1234')
|
||||
self.assertTrue(resp)
|
||||
@@ -3,7 +3,7 @@ gearman>=2.0.2
|
||||
pbr>=0.5.21,<1.0
|
||||
python-daemon>=1.6
|
||||
python-logstash
|
||||
python_novaclient<2.14.0
|
||||
python_novaclient>=2.14.1,<2.14.2
|
||||
python_swiftclient>=1.3.0
|
||||
requests>=1.0.0
|
||||
dogapi
|
||||
|
||||
Reference in New Issue
Block a user