From 3308e276481a7160adb58b9c1cad7327543c47cc Mon Sep 17 00:00:00 2001 From: Steven Hardy Date: Tue, 16 Oct 2012 17:24:53 +0100 Subject: [PATCH] heat tests : Remove utils.Stack getter methods Remove the get_*_client getter methods, as they aren't actually doing anything, so just access the attributes Change-Id: Ic6740bdfe7d44c40b9fdf9fc4d03f8eddaf9a740 Signed-off-by: Steven Hardy --- heat/tests/functional/test_CFN_API_Actions.py | 24 ++++++----------- .../functional/test_CFN_API_Actions_Boto.py | 25 ++++++----------- .../functional/test_CFN_API_UpdateStack.py | 3 +-- ..._WordPress_Single_Instance_With_EBS_EIP.py | 5 ++-- ...test_WordPress_Single_Instance_With_EIP.py | 5 ++-- heat/tests/functional/util.py | 27 ++++--------------- 6 files changed, 26 insertions(+), 63 deletions(-) diff --git a/heat/tests/functional/test_CFN_API_Actions.py b/heat/tests/functional/test_CFN_API_Actions.py index f50335a482..5c8fa199f0 100644 --- a/heat/tests/functional/test_CFN_API_Actions.py +++ b/heat/tests/functional/test_CFN_API_Actions.py @@ -112,8 +112,7 @@ class CfnApiFunctionalTest(unittest.TestCase): self.assertTrue(ver.verify_wordpress(stack_url)) def testListStacks(self): - client = self.stack.get_heat_client() - response = client.list_stacks() + response = self.stack.heatclient.list_stacks() prefix = '/ListStacksResponse/ListStacksResult/StackSummaries/member' stack_id = self.stack.response_xml_item(response, prefix, "StackId") @@ -146,10 +145,9 @@ class CfnApiFunctionalTest(unittest.TestCase): print "ListStacks : OK" def testDescribeStacks(self): - client = self.stack.get_heat_client() parameters = {} parameters['StackName'] = self.stack.stackname - response = client.describe_stacks(**parameters) + response = self.stack.heatclient.describe_stacks(**parameters) prefix = '/DescribeStacksResponse/DescribeStacksResult/Stacks/member' stack_id = self.stack.response_xml_item(response, prefix, "StackId") @@ -222,10 +220,9 @@ class CfnApiFunctionalTest(unittest.TestCase): print "DescribeStacks : OK" def testDescribeStackEvents(self): - client = self.stack.get_heat_client() parameters = {} parameters['StackName'] = self.stack.stackname - response = client.list_stack_events(**parameters) + response = self.stack.heatclient.list_stack_events(**parameters) prefix = '/DescribeStackEventsResponse/DescribeStackEventsResult/' +\ 'StackEvents/member[LogicalResourceId="' +\ self.logical_resource_name + '" and ResourceStatus="' +\ @@ -277,10 +274,9 @@ class CfnApiFunctionalTest(unittest.TestCase): print "DescribeStackEvents : OK" def testGetTemplate(self): - client = self.stack.get_heat_client() parameters = {} parameters['StackName'] = self.stack.stackname - response = client.get_template(**parameters) + response = self.stack.heatclient.get_template(**parameters) prefix = '/GetTemplateResponse/GetTemplateResult' # Extract the JSON TemplateBody and prove it parses @@ -298,10 +294,9 @@ class CfnApiFunctionalTest(unittest.TestCase): print "GetTemplate : OK" def testDescribeStackResource(self): - client = self.stack.get_heat_client() parameters = {'StackName': self.stack.stackname, 'LogicalResourceId': self.logical_resource_name} - response = client.describe_stack_resource(**parameters) + response = self.stack.heatclient.describe_stack_resource(**parameters) prefix = '/DescribeStackResourceResponse/DescribeStackResourceResult'\ + '/StackResourceDetail' @@ -344,10 +339,9 @@ class CfnApiFunctionalTest(unittest.TestCase): print "DescribeStackResource : OK" def testDescribeStackResources(self): - client = self.stack.get_heat_client() parameters = {'NameOrPid': self.stack.stackname, 'LogicalResourceId': self.logical_resource_name} - response = client.describe_stack_resources(**parameters) + response = self.stack.heatclient.describe_stack_resources(**parameters) prefix = '/DescribeStackResourcesResponse/' +\ 'DescribeStackResourcesResult/StackResources/member' @@ -385,10 +379,9 @@ class CfnApiFunctionalTest(unittest.TestCase): print "DescribeStackResources : OK" def testListStackResources(self): - client = self.stack.get_heat_client() parameters = {} parameters['StackName'] = self.stack.stackname - response = client.list_stack_resources(**parameters) + response = self.stack.heatclient.list_stack_resources(**parameters) prefix = '/ListStackResourcesResponse/ListStackResourcesResult' +\ '/StackResourceSummaries/member' @@ -419,11 +412,10 @@ class CfnApiFunctionalTest(unittest.TestCase): print "ListStackResources : OK" def testValidateTemplate(self): - client = self.stack.get_heat_client() # Use stack.format_parameters to get the TemplateBody params = self.stack.format_parameters() val_params = {'TemplateBody': params['TemplateBody']} - response = client.validate_template(**val_params) + response = self.stack.heatclient.validate_template(**val_params) prefix = '/ValidateTemplateResponse/ValidateTemplateResult' +\ '/Parameters/member' # Check the response contains all the expected paramter keys diff --git a/heat/tests/functional/test_CFN_API_Actions_Boto.py b/heat/tests/functional/test_CFN_API_Actions_Boto.py index f19a80bc4c..d45ee83f5a 100644 --- a/heat/tests/functional/test_CFN_API_Actions_Boto.py +++ b/heat/tests/functional/test_CFN_API_Actions_Boto.py @@ -116,8 +116,7 @@ class CfnApiBotoFunctionalTest(unittest.TestCase): self.assertTrue(ver.verify_wordpress(stack_url)) def testListStacks(self): - client = self.stack.get_heat_client() - response = client.list_stacks() + response = self.stack.heatclient.list_stacks() prefix = '/ListStacksResponse/ListStacksResult/StackSummaries/member' # Extract the StackSummary for this stack @@ -142,10 +141,9 @@ class CfnApiBotoFunctionalTest(unittest.TestCase): print "ListStacks : OK" def testDescribeStacks(self): - client = self.stack.get_heat_client() parameters = {} parameters['StackName'] = self.stack.stackname - response = client.describe_stacks(**parameters) + response = self.stack.heatclient.describe_stacks(**parameters) # Extract the Stack object for this stack stacks = [s for s in response @@ -200,11 +198,9 @@ class CfnApiBotoFunctionalTest(unittest.TestCase): print "DescribeStacks : OK" def testDescribeStackEvents(self): - - client = self.stack.get_heat_client() parameters = {} parameters['StackName'] = self.stack.stackname - response = client.list_stack_events(**parameters) + response = self.stack.heatclient.list_stack_events(**parameters) events = [e for e in response if e.logical_resource_id == self.logical_resource_name and e.resource_status == self.logical_resource_status] @@ -239,10 +235,9 @@ class CfnApiBotoFunctionalTest(unittest.TestCase): print "DescribeStackEvents : OK" def testGetTemplate(self): - client = self.stack.get_heat_client() parameters = {} parameters['StackName'] = self.stack.stackname - response = client.get_template(**parameters) + response = self.stack.heatclient.get_template(**parameters) self.assertTrue(response != None) result = response['GetTemplateResponse']['GetTemplateResult'] @@ -259,10 +254,9 @@ class CfnApiBotoFunctionalTest(unittest.TestCase): print "GetTemplate : OK" def testDescribeStackResource(self): - client = self.stack.get_heat_client() parameters = {'StackName': self.stack.stackname, 'LogicalResourceId': self.logical_resource_name} - response = client.describe_stack_resource(**parameters) + response = self.stack.heatclient.describe_stack_resource(**parameters) # Note boto_client response for this is a dict, if upstream # pull request ever gets merged, this will change, see note/ @@ -299,10 +293,9 @@ class CfnApiBotoFunctionalTest(unittest.TestCase): print "DescribeStackResource : OK" def testDescribeStackResources(self): - client = self.stack.get_heat_client() parameters = {'NameOrPid': self.stack.stackname, 'LogicalResourceId': self.logical_resource_name} - response = client.describe_stack_resources(**parameters) + response = self.stack.heatclient.describe_stack_resources(**parameters) self.assertEqual(len(response), 1) res = response[0] @@ -328,10 +321,9 @@ class CfnApiBotoFunctionalTest(unittest.TestCase): print "DescribeStackResources : OK" def testListStackResources(self): - client = self.stack.get_heat_client() parameters = {} parameters['StackName'] = self.stack.stackname - response = client.list_stack_resources(**parameters) + response = self.stack.heatclient.list_stack_resources(**parameters) self.assertEqual(len(response), 1) res = response[0] @@ -353,11 +345,10 @@ class CfnApiBotoFunctionalTest(unittest.TestCase): print "ListStackResources : OK" def testValidateTemplate(self): - client = self.stack.get_heat_client() # Use stack.format_parameters to get the TemplateBody params = self.stack.format_parameters() val_params = {'TemplateBody': params['TemplateBody']} - response = client.validate_template(**val_params) + response = self.stack.heatclient.validate_template(**val_params) # Check the response contains all the expected paramter keys templ_params = ['DBUsername', 'LinuxDistribution', 'InstanceType', 'DBRootPassword', 'KeyName', 'DBPassword', 'DBName'] diff --git a/heat/tests/functional/test_CFN_API_UpdateStack.py b/heat/tests/functional/test_CFN_API_UpdateStack.py index 7a3f416cac..feae070457 100644 --- a/heat/tests/functional/test_CFN_API_UpdateStack.py +++ b/heat/tests/functional/test_CFN_API_UpdateStack.py @@ -123,10 +123,9 @@ class CfnApiUpdateStackFunctionalTest(unittest.TestCase): self.assertTrue(tries < 500) # Now use DescribeStacks to check the parameter is updated - client = self.stack.get_heat_client() parameters = {} parameters['StackName'] = self.stack.stackname - response = client.describe_stacks(**parameters) + response = self.stack.heatclient.describe_stacks(**parameters) prefix = '/DescribeStacksResponse/DescribeStacksResult/Stacks/member' # value for each key, then check the extracted value param_prefix = prefix + '/Parameters/member[ParameterKey="DBUsername"]' diff --git a/heat/tests/functional/test_WordPress_Single_Instance_With_EBS_EIP.py b/heat/tests/functional/test_WordPress_Single_Instance_With_EBS_EIP.py index e4a4951f83..d0c74e500d 100644 --- a/heat/tests/functional/test_WordPress_Single_Instance_With_EBS_EIP.py +++ b/heat/tests/functional/test_WordPress_Single_Instance_With_EBS_EIP.py @@ -53,13 +53,12 @@ class WordPressEBSEIPFunctionalTest(unittest.TestCase): print "Wordpress installation detected" # 2. check floating ip assignment - nclient = self.stack.get_nova_client() - if len(nclient.floating_ips.list()) == 0: + if len(self.stack.novaclient.floating_ips.list()) == 0: print 'zero floating IPs detected' self.assertTrue(False) else: found = 0 - mylist = nclient.floating_ips.list() + mylist = self.stack.novaclient.floating_ips.list() for item in mylist: if item.instance_id == self.stack.instance_phys_ids()[0]: print 'floating IP found', item.ip diff --git a/heat/tests/functional/test_WordPress_Single_Instance_With_EIP.py b/heat/tests/functional/test_WordPress_Single_Instance_With_EIP.py index 7a2d670dda..ce0fd8fae9 100644 --- a/heat/tests/functional/test_WordPress_Single_Instance_With_EIP.py +++ b/heat/tests/functional/test_WordPress_Single_Instance_With_EIP.py @@ -53,13 +53,12 @@ class WordPressEIPFunctionalTest(unittest.TestCase): print "Wordpress installation detected" # 2. check floating ip assignment - nclient = self.stack.get_nova_client() - if len(nclient.floating_ips.list()) == 0: + if len(self.stack.novaclient.floating_ips.list()) == 0: print 'zero floating IPs detected' self.assertTrue(False) else: found = 0 - mylist = nclient.floating_ips.list() + mylist = self.stack.novaclient.floating_ips.list() for item in mylist: if item.instance_id == self.stack.instance_phys_ids()[0]: print 'floating IP found', item.ip diff --git a/heat/tests/functional/util.py b/heat/tests/functional/util.py index 74946f6250..736d85702d 100644 --- a/heat/tests/functional/util.py +++ b/heat/tests/functional/util.py @@ -333,6 +333,9 @@ class Stack(object): 'keystone', 'keystone authentication required') + self.glanceclient = glance_client.Client(host="0.0.0.0", port=9292, + use_ssl=False, auth_tok=None, creds=self.creds) + self.prepare_jeos(distribution, arch, jeos_type) self.novaclient = nova_client.Client(self.creds['username'], @@ -439,8 +442,7 @@ class Stack(object): def cleanup(self): parameters = {'StackName': self.stackname} - c = self.get_heat_client() - c.delete_stack(**parameters) + self.heatclient.delete_stack(**parameters) print 'Waiting for stack deletion to be completed' tries = 0 @@ -456,27 +458,9 @@ class Stack(object): if end_state is not None: self.testcase.assertEqual(end_state, 'DELETE_COMPLETE') - def get_nova_client(self): - if self.novaclient != None: - return self.novaclient - return None - - def get_glance_client(self): - if self.glanceclient != None: - return self.glanceclient - return None - - def get_heat_client(self): - if self.heatclient != None: - return self.heatclient - return None - def prepare_jeos(self, p_os, arch, type): imagename = p_os + '-' + arch + '-' + type - self.glanceclient = glance_client.Client(host="0.0.0.0", port=9292, - use_ssl=False, auth_tok=None, creds=self.creds) - # skip creating jeos if image already available if not self.poll_glance(self.glanceclient, imagename, False): self.testcase.assertEqual(os.geteuid(), 0, @@ -517,8 +501,7 @@ class Stack(object): ''' # Get the DescribeStacks result for this stack parameters = {'StackName': self.stackname} - c = self.get_heat_client() - result = c.describe_stacks(**parameters) + result = self.heatclient.describe_stacks(**parameters) return self._find_stack_output(result, output_key) def _find_stack_output(self, result, output_key):