Esempio n. 1
0
 def test_cached_versions_are_equal(self):
     step = SecondConditionalStop()
     data = mock_test_data.get_pipeline_data()
     # No cache entry
     data[data_defs.CACHE_ENTRY] = None
     self.assertFalse(step.cached_versions_are_equal(data))
     # All equal
     data[data_defs.CACHE_ENTRY] = mock_test_data.get_mock_cache_entry()
     self.assertTrue(step.cached_versions_are_equal(data))
     # Different static cache version
     data[data_defs.CACHE_ENTRY][cache_defs.IMAGE_VERSIONS][0][
         data_defs.IMG_VERSION] = '2.0.2_123ert'
     self.assertFalse(step.cached_versions_are_equal(data))
     data[data_defs.CACHE_ENTRY] = mock_test_data.get_mock_cache_entry()
     # Different local static version
     data[data_defs.SERVICES][0][data_defs.S_IMAGE][
         data_defs.IMG_VERSION] = '12.0.1_yui321'
     self.assertFalse(step.cached_versions_are_equal(data))
     data[data_defs.CACHE_ENTRY] = mock_test_data.get_mock_cache_entry()
     # Different cached image name
     data[data_defs.CACHE_ENTRY][cache_defs.IMAGE_VERSIONS][0][
         data_defs.IMG_NAME] = 'another-image'
     self.assertFalse(step.cached_versions_are_equal(data))
     data[data_defs.CACHE_ENTRY] = mock_test_data.get_mock_cache_entry()
     # Different local semver version
     data[data_defs.SERVICES][0][data_defs.S_IMAGE][
         data_defs.IMG_BEST_SEMVER_MATCH] = '12.0.1_yui321'
     self.assertFalse(step.cached_versions_are_equal(data))
Esempio n. 2
0
 def test_verify_services(self):
     step = VerifyPipelineData()
     data = mock_test_data.get_pipeline_data()
     try:
         step.verify_services(data)
     except:
         self.fail('Failed to verify services')
Esempio n. 3
0
 def verify_deploy_labels(self):
     step = VerifyPipelineData()
     data = mock_test_data.get_pipeline_data()
     try:
         step.verify_deploy_labels(data)
     except:
         self.fail('Failed to verify deploy labels')
Esempio n. 4
0
 def test_get_enumerated_services(self):
     pipeline_data = mock_test_data.get_pipeline_data()
     service_data = []
     for i, service in pipeline_data_utils.get_enumerated_services(
             pipeline_data):
         service_data.append((i, service[data_defs.S_NAME]))
     self.assertEqual(service_data, [(0, 'web'), (1, 'api')])
Esempio n. 5
0
 def test_get_labels(self):
     pipeline_data = mock_test_data.get_pipeline_data()
     service = pipeline_data[data_defs.SERVICES][0]
     label_data = []
     for name, value in pipeline_data_utils.get_labels(service):
         label_data.append((name, value))
     self.assertEqual(len(label_data), 10)
Esempio n. 6
0
 def test_run_step(self):
     pipeline_data = mock_test_data.get_pipeline_data()
     try:
         os.environ[
             environment.FRONT_END_RULE_LABEL] = 'traefik.frontend.rule'
         step = VerifyFrontendRule()
         step.run_step(pipeline_data)
         os.environ[environment.FRONT_END_RULE_LABEL] = 'doesnt.exist'
         step.run_step(pipeline_data)
     except Exception:
         self.fail()
     os.environ[environment.FRONT_END_RULE_LABEL] = 'test.rule'
     pipeline_data[data_defs.SERVICES][0][data_defs.S_DEPLOY_LABELS] = [
         'test.rule=PathPrefixStrip:/'
     ]
     self.assertRaises(DeploymentError, step.run_step, pipeline_data)
     # Application exclusion test
     try:
         os.environ[
             environment.FRONT_END_RULE_LABEL] = 'traefik.frontend.rule'
         pipeline_data[data_defs.APPLICATION_NAME] = 'tamarack'
         pipeline_data[data_defs.SERVICES][0][data_defs.S_DEPLOY_LABELS] = [
             'traefik.frontend.rule=PathPrefixStrip:/'
         ]
         step.run_step(pipeline_data)
     except Exception:
         self.fail()
Esempio n. 7
0
 def test_run_step(self):
     pipeline_data = mock_test_data.get_pipeline_data()
     pipeline_data[data_defs.CACHE_ENTRY] = None
     step = FirstConditionalStop()
     step.stop_pipeline = mock.Mock()
     # semver usage + changed hash: no stop
     step.run_step(pipeline_data)
     step.stop_pipeline.assert_not_called()
     pipeline_data[data_defs.CACHE_ENTRY] = {
         cache_defs.DIRECTORY_MD5: 'alejfbabovudbasepvbsoev'
     }
     step.stop_pipeline.reset_mock()
     # semver usage + equal hash: no stop
     step.run_step(pipeline_data)
     step.stop_pipeline.assert_not_called()
     pipeline_data[data_defs.SERVICES][1][data_defs.S_IMAGE][
         data_defs.IMG_IS_SEMVER] = False
     step.stop_pipeline.reset_mock()
     # no semver usage + equal hash: stop
     step.run_step(pipeline_data)
     step.stop_pipeline.assert_called_once()
     pipeline_data[data_defs.STACK_FILE_DIR_HASH] = 'not_equal'
     step.stop_pipeline.reset_mock()
     # no semver usage + changed hash: no stop
     step.run_step(pipeline_data)
     step.stop_pipeline.assert_not_called()
Esempio n. 8
0
 def test_get_service_image_version(self):
     step = SecondConditionalStop()
     data = mock_test_data.get_pipeline_data()
     result = step.get_service_image_version(data[data_defs.SERVICES][0])
     self.assertEqual(result, '2.0.1_abc123')
     result = step.get_service_image_version(data[data_defs.SERVICES][1])
     self.assertEqual(result, '0.1.4_abc123')
Esempio n. 9
0
 def test_generate_image_versions(self):
     step = WriteCacheEntry()
     pipeline_data = mock_test_data.get_pipeline_data()
     result = step.generate_image_versions(pipeline_data)
     self.assertTrue(len(result), 2)
     self.assertEqual(result[0][data_defs.IMG_NAME], 'kth-azure-app')
     self.assertEqual(result[0][data_defs.IMG_VERSION], '2.0.1_abc123')
     self.assertEqual(result[1][data_defs.IMG_NAME], 'redis')
     self.assertEqual(result[1][data_defs.IMG_VERSION], '0.1.4_abc123')
Esempio n. 10
0
 def test_get_frontend_rule(self):
     pipeline_data = mock_test_data.get_pipeline_data()
     label = 'traefik.frontend.rule'
     step = VerifyFrontendRule()
     result = step.get_frontend_rule(label, pipeline_data)
     self.assertEqual(result, 'PathPrefix:/kth-azure-app')
     pipeline_data[data_defs.SERVICES][0][data_defs.S_DEPLOY_LABELS] = []
     result = step.get_frontend_rule(label, pipeline_data)
     self.assertIsNone(result)
Esempio n. 11
0
 def test_service_uses_semver(self):
     pipeline_data = mock_test_data.get_pipeline_data()
     step = FirstConditionalStop()
     result = step.service_uses_semver(pipeline_data)
     self.assertTrue(result)
     pipeline_data[data_defs.SERVICES][1][data_defs.S_IMAGE][
         data_defs.IMG_IS_SEMVER] = False
     result = step.service_uses_semver(pipeline_data)
     self.assertFalse(result)
Esempio n. 12
0
 def test_generate_cache_entry(self):
     step = WriteCacheEntry()
     pipeline_data = mock_test_data.get_pipeline_data()
     image_versions = step.generate_image_versions(pipeline_data)
     result = step.generate_cache_entry(pipeline_data, image_versions)
     self.assertEqual(
         result, {
             cache_defs.DIRECTORY_MD5: 'alejfbabovudbasepvbsoev',
             cache_defs.IMAGE_VERSIONS: image_versions
         })
Esempio n. 13
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')
Esempio n. 14
0
 def test_get_service_labels(self):
     step = ReportSuccess()
     service = mock_test_data.get_pipeline_data()[data_defs.SERVICES][0]
     expected = {
         'slackChannels': '#one,#two',
         'publicNameSwedish': 'Testnings API',
         'publicNameEnglish': 'Test API',
         'descriptionSwedish': 'API för kurssystem',
         'descriptionEnglish': 'API for course system',
         'importance': 'medium',
         'detectifyProfileTokens': 'abc123,zxc456',
         'monitorUrl': '/_monitor'
     }
     result = step.get_service_labels({}, service)
     self.assertEqual(result, expected)
Esempio n. 15
0
 def test_run_step(self):
     step = StopExcludedApps()
     step.stop_pipeline = Mock()
     pipeline_data = mock_test_data.get_pipeline_data()
     os.environ[environment.EXCLUDED_APPS] = "app1,app2"
     step.run_step(pipeline_data)
     step.stop_pipeline.assert_not_called()
     step.stop_pipeline.reset_mock()
     os.environ[environment.EXCLUDED_APPS] = ""
     step.run_step(pipeline_data)
     step.stop_pipeline.assert_not_called()
     step.stop_pipeline.reset_mock()
     os.environ[environment.EXCLUDED_APPS] = "app1,kth-azure-app"
     step.run_step(pipeline_data)
     step.stop_pipeline.assert_called_once()
     step.stop_pipeline.reset_mock()
     del os.environ[environment.EXCLUDED_APPS]
     step.run_step(pipeline_data)
     step.stop_pipeline.assert_not_called()
Esempio n. 16
0
 def test_get_services(self):
     pipeline_data = mock_test_data.get_pipeline_data()
     service_names = []
     for service in pipeline_data_utils.get_services(pipeline_data):
         service_names.append(service[data_defs.S_NAME])
     self.assertEqual(service_names, ['web', 'api'])
Esempio n. 17
0
 def test_service_uses_semver(self):
     pipeline_data = mock_test_data.get_pipeline_data()
     service = pipeline_data[data_defs.SERVICES][0]
     self.assertFalse(pipeline_data_utils.service_uses_semver(service))
     service = pipeline_data[data_defs.SERVICES][1]
     self.assertTrue(pipeline_data_utils.service_uses_semver(service))
Esempio n. 18
0
 def test_service_env_as_string(self):
     pipeline_data = mock_test_data.get_pipeline_data()
     service = pipeline_data[data_defs.SERVICES][0]
     env_string = pipeline_data_utils.service_env_as_string(service)
     self.assertEqual(env_string, 'env1=key1 env2=key2')
Esempio n. 19
0
 def test_get_cache_key(self):
     pipeline_data = mock_test_data.get_pipeline_data()
     os.environ[environment.MANAGEMENT_RES_GRP] = 'dev-ev'
     cache_key = get_cache_key(pipeline_data)
     self.assertEqual(cache_key,
                      'dev-ev/test/path/for/real/docker-stack.yml')