class TestAudreyAgentServiceV2(TestAudreyAgentServiceV1): ''' Class for exercising the parsing of the Required Configs from the CS. ''' def setUp(self): self.factory = AudreyFactory(2) self.tooling = self.factory.tooling(TARFILE, TOOLING_DIR) self.service = self.factory.service('test_service', self.tooling)
def main(): ''' Description: This script will be used on EC2 for configuring the running instance based on Cloud Engine configuration supplied at launch time in the user data. Config Server Status: 200 HTTP OK - Success and no more data of this type 202 HTTP Accepted - Success and more data of this type 404 HTTP Not Found - This may be temporary so try again ''' # parse the args and setup logging conf = parse_args() log_file = {} if 'pwd' in conf and conf.pwd: log_file = {'logfile_name': 'audrey.log'} logger = setup_logging(level=conf.log_level, **log_file) if not conf.endpoint: # discover the cloud I'm on # update the conf with the user data #conf = dict(vars(conf).items() + user_data.discover().read().items()) vars(conf).update(user_data.discover().read().items()) # ensure the conf is a dictionary, not a namespace if hasattr(conf, '__dict__'): conf = vars(conf) logger.info('Invoked audrey main') # Create the Client Object and test connectivity # to CS by negotiating the api version client = CSClient(**conf) client.test_connection() # Get the agent object agent = AudreyFactory(client.api_version).agent # run the agent agent(conf).run()
def setUp(self): self.tool_dir = os.path.join(os.path.abspath('.'), 'test_tooling') self.tooling = Tooling(TARFILE, self.tool_dir) self.factory = AudreyFactory(1)
def setUp(self): super(TestAudreyAgentToolingV2, self).setUp() self.factory = AudreyFactory(2)
def setUp(self): self.factory = AudreyFactory(1) self.tooling = self.factory.tooling(TARFILE, TOOLING_DIR) self.service = self.factory.service('test_service', self.tooling)
class TestAudreyAgentServiceV1(unittest.TestCase): ''' Class for exercising the parsing of the Required Configs from the CS. ''' def setUp(self): self.factory = AudreyFactory(1) self.tooling = self.factory.tooling(TARFILE, TOOLING_DIR) self.service = self.factory.service('test_service', self.tooling) def test_success_service_n_provides(self): ''' Success case: - Exercise service().parse_require_config() with valid input ''' # Exersise code segment services = self.factory.service.parse_require_config( DUMMY_SERVICE_CONFIG_DATA, self.tooling) # Validate results self.assertEqual(services[0].name, 'jon1') self.assertEqual(services[1].name, 'jon2') ## ## TODO: verify the env variable else where #for service in services: # for param in service.params: # name_val = param.split('&') # env_var = 'AUDREY_VAR_' + service.name + '_' + name_val[0] # cmd = ['/usr/bin/printenv', env_var] # ret = run_cmd(cmd) # self.assertEqual(ret['out'][:-1], \ # VALIDATE_SERVICE_CONFIG_DATA[env_var]) def test_success_empty_source(self): ''' Success case: - Exercise service().parse_require_config() with valid empty input ''' src = '||' services = self.service.parse_require_config(src, self.tooling) self.assertEqual(services, []) def test_success_empty_service(self): ''' Failure case: - Exercise service().parse_require_config() with valid input ''' services = self.factory.service.parse_require_config( DUMMY_NO_SERVICE_CONFIG_DATA, self.tooling) self.assertEqual(services[0].name, '') self.assertEqual(services[1].name, 'jon2') ## ## TODO: verify the env variable else where #for service in services: # for param in service.params: # name_val = param.split('&') # env_var = 'AUDREY_VAR_' + name_val[0] # cmd = ['/usr/bin/printenv', env_var] # ret = run_cmd(cmd) # self.assertEqual(ret['out'][:-1], \ # VALIDATE_NO_SERVICE_CONFIG_DATA[env_var]) def test_failure_no_services_name(self): ''' Failure case: - Exercise service().parse_require_config() with valid input The slight difference between this test and test_success_empty_services is the success case has an empty service name indicated by "||": |service||paramseters and the failure case has no service name: |service|paramseters ''' # Establish valid test data: src = '|service' \ '|parameters|jon_server_ip&' + base64.b64encode('192.168.1.1') + \ '|jon_server_ip_2&' + base64.b64encode('192.168.1.2') + \ '|jon_server_ip_3&' + base64.b64encode('192.168.1.3') + \ '|service|jon2|' validation_dict = {'AUDREY_VAR_jon_server_ip': '192.168.1.1', 'AUDREY_VAR_jon_server_ip_2': '192.168.1.2', 'AUDREY_VAR_jon_server_ip_3': '192.168.1.3'} self.assertRaises(AAError, self.factory.service.parse_require_config, src, self.tooling) def test_failure_bad_service_name(self): ''' Failure case: - Exercise service().parse_require_config() with valid input ''' src = '|service|parameters|' self.assertRaises(AAError, self.factory.service.parse_require_config, src, self.tooling) def test_failure_service_tag_not_found(self): ''' Failure Case: - |service| not in src to service().parse_require_config() ''' src = '|notservice|blah|' self.assertRaises(AAError, self.factory.service.parse_require_config, src, self.tooling) def test_failure_no_amp_delim(self): ''' Failure Case: - no delim in param token ''' src = '|service|blah|parameters|blah|' self.assertRaises(AAError, self.factory.service.parse_require_config, src, self.tooling)
def setUp(self): self.factory = AudreyFactory(1) self.tooling = self.factory.tooling(TARFILE, TOOLING_DIR)
class TestAudreyAgentProvidesV1(unittest.TestCase): ''' Class for exercising the parsing of the Provides ParametersConfigs from the CS. ''' def setUp(self): self.factory = AudreyFactory(1) self.tooling = self.factory.tooling(TARFILE, TOOLING_DIR) def test_success_parameters(self): ''' Success case: - Exercise parse_provides() and generate_provides() with valid input ''' src = '|operatingsystem&is_virtual|' expected = ['operatingsystem', 'is_virtual'] provides = self.factory.provides() provides.parse_cs_str(src, self.tooling) provides_str = provides.generate_cs_str() self.assertEqual(expected, provides.keys()) # The values are not validatable because they are unpredictable # but all the expected parameters should be returned. # Note: %7C is the encoded |, %26 is the encoded & self.assertTrue('audrey_data=%7Coperatingsystem' in provides_str) for param in expected: self.assertIn(param, provides) def test_success_empty_provides(self): ''' Success case: - Exercise parse_provides() and generate_provides() with valid demlims but empty input ''' src = '||' provides = self.factory.provides() provides.parse_cs_str(src, self.tooling) provides_str = provides.generate_cs_str() self.assertEqual(provides.keys(), []) self.assertEqual(provides.generate_cs_str(), 'audrey_data=%7C%26%7C') def test_success_no_provides(self): ''' Success case: - Exercise parse_provides() and generate_provides() with valid input - Containging an unavailable parameter ''' src = '|uptime_days&unavailable_dogs&ipaddress|' #expected = ['uptime_days', 'unavailable_dogs', 'ipaddress'] expected = ['ipaddress', 'uptime_days', 'unavailable_dogs'] provides = self.factory.provides() provides.parse_cs_str(src, self.tooling) provides_str = provides.generate_cs_str() # Validate results self.assertEqual(provides.keys(), expected) # The values are not validatable because they are unpredictable # but all the expected parameters should be returned. # Note: %7C is the encoded |, %26 is the encoded & for param in expected: self.assertIn(param, provides) # Confirm unavailable parameters return None self.assertEqual(provides['unavailable_dogs'], None) def test_success_one_parameters(self): ''' Success case: - Exercise parse_provides() and generate_provides() with valid input - with only one parameter ''' # Establish valid test data: src = '|uptime_days|' expected = ['uptime_days'] # Exersise code segment provides = self.factory.provides() provides.parse_cs_str(src, self.tooling) provides_str = provides.generate_cs_str() # Validate results self.assertEqual(provides.keys(), expected) # The values are not validatable because they are unpredictable # but all the expected parameters should be returned. # Note: %7C is the encoded |, %26 is the encoded & for param in expected: self.assertIn(param, provides) def test_success_one_parameter(self): ''' Success case: - Exercise parse_provides() and generate_provides() with valid input - With only one parameter which is unavailable ''' src = '|unavailable_dogs|' expected = ['unavailable_dogs'] provides = self.factory.provides() provides.parse_cs_str(src, self.tooling) provides_str = provides.generate_cs_str() self.assertEqual(provides.keys(), expected) # The values are not validatable because they are unpredictable # but all the expected parameters should be returned. # Note: %7C is the encoded |, %26 is the encoded & for param in expected: self.assertIn(param, provides) # Confirm unavailable parameters return an empty string. self.assertIn('unavailable_dogs', provides) def test_failure_missing_delimiter(self): ''' Failure case: - Exercise parse_provides() and generate_provides() with invalid input - missing leading delimiter ''' src = 'unavailable_dogs|' expected = ['unavailable_dogs'] provides = self.factory.provides() self.assertRaises(AAError, self.factory.provides().parse_cs_str, src, self.tooling)
class TestAudreyAgentServiceV1(unittest.TestCase): ''' Class for exercising the parsing of the Required Configs from the CS. ''' def setUp(self): self.factory = AudreyFactory(1) self.tooling = self.factory.tooling(TARFILE, TOOLING_DIR) self.service = self.factory.service('test_service', self.tooling) def test_success_service_n_provides(self): ''' Success case: - Exercise service().parse_require_config() with valid input ''' # Exersise code segment services = self.factory.service.parse_require_config( DUMMY_SERVICE_CONFIG_DATA, self.tooling) # Validate results self.assertEqual(services[0].name, 'jon1') self.assertEqual(services[1].name, 'jon2') ## ## TODO: verify the env variable else where #for service in services: # for param in service.params: # name_val = param.split('&') # env_var = 'AUDREY_VAR_' + service.name + '_' + name_val[0] # cmd = ['/usr/bin/printenv', env_var] # ret = run_cmd(cmd) # self.assertEqual(ret['out'][:-1], \ # VALIDATE_SERVICE_CONFIG_DATA[env_var]) def test_success_empty_source(self): ''' Success case: - Exercise service().parse_require_config() with valid empty input ''' src = '||' services = self.service.parse_require_config(src, self.tooling) self.assertEqual(services, []) def test_success_empty_service(self): ''' Failure case: - Exercise service().parse_require_config() with valid input ''' services = self.factory.service.parse_require_config( DUMMY_NO_SERVICE_CONFIG_DATA, self.tooling) self.assertEqual(services[0].name, '') self.assertEqual(services[1].name, 'jon2') ## ## TODO: verify the env variable else where #for service in services: # for param in service.params: # name_val = param.split('&') # env_var = 'AUDREY_VAR_' + name_val[0] # cmd = ['/usr/bin/printenv', env_var] # ret = run_cmd(cmd) # self.assertEqual(ret['out'][:-1], \ # VALIDATE_NO_SERVICE_CONFIG_DATA[env_var]) def test_failure_no_services_name(self): ''' Failure case: - Exercise service().parse_require_config() with valid input The slight difference between this test and test_success_empty_services is the success case has an empty service name indicated by "||": |service||paramseters and the failure case has no service name: |service|paramseters ''' # Establish valid test data: src = '|service' \ '|parameters|jon_server_ip&' + base64.b64encode('192.168.1.1') + \ '|jon_server_ip_2&' + base64.b64encode('192.168.1.2') + \ '|jon_server_ip_3&' + base64.b64encode('192.168.1.3') + \ '|service|jon2|' validation_dict = { 'AUDREY_VAR_jon_server_ip': '192.168.1.1', 'AUDREY_VAR_jon_server_ip_2': '192.168.1.2', 'AUDREY_VAR_jon_server_ip_3': '192.168.1.3' } self.assertRaises(AAError, self.factory.service.parse_require_config, src, self.tooling) def test_failure_bad_service_name(self): ''' Failure case: - Exercise service().parse_require_config() with valid input ''' src = '|service|parameters|' self.assertRaises(AAError, self.factory.service.parse_require_config, src, self.tooling) def test_failure_service_tag_not_found(self): ''' Failure Case: - |service| not in src to service().parse_require_config() ''' src = '|notservice|blah|' self.assertRaises(AAError, self.factory.service.parse_require_config, src, self.tooling) def test_failure_no_amp_delim(self): ''' Failure Case: - no delim in param token ''' src = '|service|blah|parameters|blah|' self.assertRaises(AAError, self.factory.service.parse_require_config, src, self.tooling)