Beispiel #1
0
 def test_parse_registry(self):
     test_data = mock_test_data.get_parsed_stack_content()
     step = ParseImageData()
     service = test_data['services']['api']
     self.assertEqual(step.parse_registry(service), 'test_registry')
     service['image'] = 'no_registry:1.2.3'
     self.assertIsNone(step.parse_registry(service))
Beispiel #2
0
 def test_has_secrets_env_file(self):
     pipeline_data = {data_defs.STACK_FILE_PARSED_CONTENT:
                      mock_test_data.get_parsed_stack_content()}
     test = SecretVerification()
     self.assertFalse(test.has_secrets_env_file(pipeline_data))
     pipeline_data[data_defs.STACK_FILE_PARSED_CONTENT]['services']['api']['env_file'] = ['secrets.decrypted.env']
     self.assertTrue(test.has_secrets_env_file(pipeline_data))
 def test_run(self):
     test_data = mock_test_data.get_parsed_stack_content()
     pipeline_data = {data_defs.STACK_FILE_PARSED_CONTENT: test_data}
     step = InitServicePipelineData()
     result = step.run_step(pipeline_data)
     self.assertEqual(
         result[data_defs.SERVICES][0][data_defs.S_ENVIRONMENT], {})
     self.assertEqual(result[data_defs.SERVICES][0][data_defs.S_NAME],
                      'web')
     self.assertEqual(
         result[data_defs.SERVICES][0][data_defs.S_DEPLOY_LABELS], [])
     self.assertEqual(result[data_defs.SERVICES][1][data_defs.S_NAME],
                      'api')
     deploy_labels = [
         label.split('=') for label in result[data_defs.SERVICES][1][
             data_defs.S_DEPLOY_LABELS]
     ]
     for name, value in deploy_labels:
         if name == 'traefik.deploy' and value == 'true':
             break
     else:
         self.fail('Couldnt find traefik.deploy deploy label')
     labels = pipeline_data_utils.get_labels(result[data_defs.SERVICES][1])
     for name, value in labels:
         if name == 'se.kth.slackChannels' and value == '#team-pipeline,#ita-ops':
             break
     else:
         self.fail('Couldnt find se.kth.slackChannels label')
Beispiel #4
0
 def test_parse_version(self):
     test_data = mock_test_data.get_parsed_stack_content()
     step = ParseImageData()
     service = test_data['services']['api']
     self.assertEqual(step.parse_version(service), '1.2.3_abc456')
     service['image'] = 'registry/image'
     self.assertRaises(exceptions.DeploymentError, step.parse_version,
                       service)
Beispiel #5
0
 def test_parse_image_name(self):
     test_data = mock_test_data.get_parsed_stack_content()
     step = ParseImageData()
     service = test_data['services']['api']
     self.assertEqual(step.parse_image_name(service), 'test_image')
     service['image'] = 'registry/:1.2.3'
     self.assertRaises(exceptions.DeploymentError, step.parse_image_name,
                       service)
Beispiel #6
0
 def test_has_image(self):
     test_data = mock_test_data.get_parsed_stack_content()
     step = ParseImageData()
     service = test_data['services']['web']
     self.assertRaises(exceptions.DeploymentError, step.has_image, service)
     service = test_data['services']['api']
     try:
         step.has_image(service)
     except:
         self.fail()
Beispiel #7
0
 def test_get_semver_version_from_env(self):
     step = ImageHasSemanticVersion()
     mocked_content = mock_test_data.get_parsed_stack_content()
     pipeline_data = {data_defs.STACK_FILE_PARSED_CONTENT: mocked_content}
     value = step.get_semver_version_from_env(pipeline_data, 'web',
                                              'WEB_VERSION')
     self.assertEqual(value, '~2.1.3_abc123')
     self.assertRaises(exceptions.DeploymentError,
                       step.get_semver_version_from_env, pipeline_data,
                       'bad_service_name', 'WEB_VERSION')
Beispiel #8
0
 def test_good_resource_policy(self):
     step = ResourcePolicyChecker()
     pipeline_data = {data_defs.STACK_FILE_PARSED_CONTENT:
                      mock_test_data.get_parsed_stack_content()}
     service = pipeline_data[data_defs.STACK_FILE_PARSED_CONTENT]['services']['api']
     try:
         step.has_resource_policy(service)
         step.verify_resource_policy(service['deploy']['resources'])
     except:
         self.fail()
Beispiel #9
0
 def test_has_service_label(self):
     step = SendRecommendations()
     parsed_data = mock_test_data.get_parsed_stack_content()
     pipeline_data = {data_defs.STACK_FILE_PARSED_CONTENT: parsed_data}
     self.assertTrue(
         step.has_service_label(pipeline_data, 'se.kth.slackChannels'))
     self.assertTrue(
         step.has_service_label(pipeline_data, 'se.kth.importance'))
     self.assertFalse(
         step.has_service_label(pipeline_data, 'se.kth.missing'))
Beispiel #10
0
 def test_bad_resource_policy(self):
     step = ResourcePolicyChecker()
     pipeline_data = {data_defs.STACK_FILE_PARSED_CONTENT:
                      mock_test_data.get_parsed_stack_content()}
     service = pipeline_data[data_defs.STACK_FILE_PARSED_CONTENT]['services']['web']
     self.assertRaises(exceptions.DeploymentError, step.has_resource_policy, service)
     service['deploy'] = {}
     self.assertRaises(exceptions.DeploymentError, step.has_resource_policy, service)
     service['deploy'] = {'resources': {}}
     self.assertRaises(exceptions.DeploymentError, step.verify_resource_policy,
                       service['deploy']['resources'])
Beispiel #11
0
 def verify_parsed_environment(self):
     step = VerifyPipelineData()
     data = mock_test_data.get_pipeline_data()
     data[
         data_defs.
         STACK_FILE_PARSED_CONTENT] = mock_test_data.get_parsed_stack_content(
         )
     try:
         step.verify_parsed_environment(data)
     except:
         self.fail('Failed to verify parsed service enviroment')
Beispiel #12
0
 def test_get_parsed_services(self):
     pipeline_data = {
         data_defs.STACK_FILE_PARSED_CONTENT:
         mock_test_data.get_parsed_stack_content()
     }
     service_data = []
     for name, service in pipeline_data_utils.get_parsed_services(
             pipeline_data):
         service_data.append((name, service))
     self.assertEqual(service_data[0][0], 'web')
     self.assertIsNotNone(service_data[0][1])
     self.assertEqual(service_data[1][0], 'api')
     self.assertIsNotNone(service_data[1][1])
Beispiel #13
0
 def test_good_logging_policy(self):
     step = LoggingPolicyChecker()
     pipeline_data = {
         data_defs.STACK_FILE_PARSED_CONTENT:
         mock_test_data.get_parsed_stack_content()
     }
     service = pipeline_data[
         data_defs.STACK_FILE_PARSED_CONTENT]['services']['api']
     try:
         step.has_logging_policy(service)
         step.verify_logging_policy(service['logging'])
     except:
         self.fail()
Beispiel #14
0
 def test_bad_replicas(self):
     step = ParseReplicas()
     pipeline_data = {
         data_defs.STACK_FILE_PARSED_CONTENT:
         mock_test_data.get_parsed_stack_content()
     }
     service = pipeline_data[
         data_defs.STACK_FILE_PARSED_CONTENT]['services']['web']
     self.assertRaises(exceptions.DeploymentError, step.get_replicas,
                       service)
     service['deploy'] = {}
     self.assertRaises(exceptions.DeploymentError, step.get_replicas,
                       service)
Beispiel #15
0
 def test_good_replicas(self):
     step = ParseReplicas()
     pipeline_data = {
         data_defs.STACK_FILE_PARSED_CONTENT:
         mock_test_data.get_parsed_stack_content()
     }
     pipeline_data[data_defs.STACK_FILE_PARSED_CONTENT]['services']['web'][
         'deploy'] = {
             'replicas': 1
         }
     try:
         step.run_step(pipeline_data)
     except:
         self.fail()
     self.assertEqual(pipeline_data[data_defs.REPLICAS], 3)
Beispiel #16
0
 def test_send_label_recommendations(self):
     step = SendRecommendations()
     send_recommendations.reporter_service.handle_recommendation = mock.Mock(
     )
     step.get_random_emoji = mock.Mock(return_value=':emoji:')
     step.get_random_flavor_text = mock.Mock(return_value='Flavor text')
     pipeline_data = {
         data_defs.APPLICATION_NAME:
         'kth-azure-app',
         data_defs.STACK_FILE_PARSED_CONTENT:
         mock_test_data.get_parsed_stack_content()
     }
     step.send_label_recommendations(pipeline_data)
     send_recommendations.reporter_service.handle_recommendation.assert_any_call(
         pipeline_data, 'kth-azure-app',
         ':emoji: Flavor text\n `se.kth.description.swedish="Kort beskrivning av applikationen"`'
     )