def test_generator_with_app_name_bad_chars(self): app_name_with_underscores = "test_app" spinnaker_tags = {} raw_tags = {} http_client = _given_config_url_response_content_is( VALID_DEPLOY_CONFIG_V3) generator = ApplicationGenerator( http_client, create_deployment_id=lambda: DEPLOYMENT_ID) deployment_id, returned_application = generator.generate_application( target_namespace=ANY_NAMESPACE, release=Release(VALID_IMAGE_NAME, VALID_DEPLOY_CONFIG_URL, make_safe_name(app_name_with_underscores), app_name_with_underscores, spinnaker_tags, raw_tags)) returned_metadata = returned_application.metadata assert returned_metadata.name == make_safe_name( app_name_with_underscores) assert returned_metadata.labels["app"] == make_safe_name( app_name_with_underscores) returned_spec = returned_application.spec assert returned_spec.application == make_safe_name( app_name_with_underscores) assert returned_spec.config["annotations"]["mast"][ "originalApplicationName"] == app_name_with_underscores
def test_ingress_is_updated(self, k8s_model, object_types): _, spec_model = object_types existing_spec = spec_model( application=APPLICATION_NAME, image=VALID_IMAGE_NAME, config=yaml.safe_load(VALID_DEPLOY_CONFIG_WITH_INGRESS_1) ) k8s_model.spec = existing_spec http_client = _given_config_url_response_content_is(VALID_DEPLOY_CONFIG_WITH_INGRESS_2) deployer = Deployer(http_client, create_deployment_id=lambda: DEPLOYMENT_ID) deployer.deploy( target_namespace="default", release=Release( VALID_IMAGE_NAME, VALID_DEPLOY_CONFIG_URL, APPLICATION_NAME, APPLICATION_NAME, SPINNAKER_TAGS, RAW_TAGS, "" ) ) expected_spec = spec_model( application=APPLICATION_NAME, image=VALID_IMAGE_NAME, config=yaml.safe_load(VALID_DEPLOY_CONFIG_WITH_INGRESS_2) ) assert k8s_model.spec == expected_spec k8s_model.save.assert_called_once()
def test_deployer_creates_object_of_given_type(self, get, k8s_model, object_types, config, target_namespace, expected_namespace): http_client = _given_config_url_response_content_is(config) _, spec_model = object_types deployer = Deployer(http_client, create_deployment_id=lambda: DEPLOYMENT_ID) returned_namespace, returned_name, returned_id = deployer.deploy( target_namespace=target_namespace, release=Release(VALID_IMAGE_NAME, VALID_DEPLOY_CONFIG_URL, APPLICATION_NAME, APPLICATION_NAME, SPINNAKER_TAGS, RAW_TAGS)) assert returned_namespace == expected_namespace assert returned_name == APPLICATION_NAME assert returned_id == DEPLOYMENT_ID http_client.get.assert_called_once_with(VALID_DEPLOY_CONFIG_URL) metadata = ObjectMeta(name=APPLICATION_NAME, namespace=expected_namespace, labels={ "fiaas/deployment_id": DEPLOYMENT_ID, "app": APPLICATION_NAME }) spec = spec_model(application=APPLICATION_NAME, image=VALID_IMAGE_NAME, config=yaml.safe_load(config)) get.assert_called_once_with(APPLICATION_NAME, expected_namespace) assert metadata == k8s_model.metadata assert spec == k8s_model.spec k8s_model.save.assert_called_once()
def test_generator_annotates_moniker_application(self, config, target_namespace, expected_namespace): spinnaker_tags = {} raw_tags = {} metadata_annotation = { "moniker.spinnaker.io/application": "unicorn", "this_is_a_number": 3, "this_is_a_floating_point_number": 3.14, "this_is_a_bool": True, } expected_metadata_annotations = { "moniker.spinnaker.io/application": "unicorn", "this_is_a_number": "3", "this_is_a_floating_point_number": "3.14", "this_is_a_bool": "True", } http_client = _given_config_url_response_content_is(config) generator = ApplicationGenerator( http_client, create_deployment_id=lambda: DEPLOYMENT_ID) deployment_id, returned_application = generator.generate_application( target_namespace=target_namespace, release=Release(VALID_IMAGE_NAME, VALID_DEPLOY_CONFIG_URL, make_safe_name(APPLICATION_NAME), APPLICATION_NAME, spinnaker_tags, raw_tags, metadata_annotation)) expected_application = BASE_PAASBETA_APPLICATION expected_application["metadata"]["namespace"] = expected_namespace expected_application["metadata"][ "annotations"] = expected_metadata_annotations assert returned_application.as_dict() == expected_application
def _annotations_verification(self, spinnaker_tags, raw_tags, exptected_paasbeta_result, deploy_config): http_client = _given_config_url_response_content_is(deploy_config) generator = ApplicationGenerator( http_client, create_deployment_id=lambda: DEPLOYMENT_ID) deployment_id, returned_paasbeta_application = generator.generate_application( target_namespace=ANY_NAMESPACE, release=Release(VALID_IMAGE_NAME, VALID_DEPLOY_CONFIG_URL, make_safe_name(APPLICATION_NAME), APPLICATION_NAME, spinnaker_tags, raw_tags)) returned_annotations = returned_paasbeta_application.spec.config[ "annotations"] assert returned_annotations == exptected_paasbeta_result
def test_generator_without_annotations(self): spinnaker_tags = {} raw_tags = {} http_client = _given_config_url_response_content_is( VALID_DEPLOY_CONFIG_V3) generator = ApplicationGenerator( http_client, create_deployment_id=lambda: DEPLOYMENT_ID) deployment_id, returned_paasbeta_application = generator.generate_application( target_namespace=ANY_NAMESPACE, release=Release(VALID_IMAGE_NAME, VALID_DEPLOY_CONFIG_URL, make_safe_name(APPLICATION_NAME), APPLICATION_NAME, spinnaker_tags, raw_tags)) assert "annotations" not in returned_paasbeta_application.spec.config
def test_generate_application(client, application_endpoint): with mock.patch.object( ApplicationGenerator, 'generate_application', return_value=("deployment_id", FiaasApplication())) as generate_application: resp = client.post(application_endpoint, data=dumps(VALID_DEPLOY_DATA), content_type="application/json") assert resp.status_code == 200 body = loads(resp.data.decode(resp.charset)) assert urlparse( body["status_url"] ).path == "/status/default-namespace/example/deployment_id/" generate_application.assert_called_with( DEFAULT_NAMESPACE, Release("test_image", "http://example.com", "example", "example", SPINNAKER_TAGS, RAW_TAGS, {}))
def test_generator_creates_object_of_given_type(self, config, target_namespace, expected_namespace): spinnaker_tags = {} raw_tags = {} http_client = _given_config_url_response_content_is(config) generator = ApplicationGenerator( http_client, create_deployment_id=lambda: DEPLOYMENT_ID) deployment_id, returned_paasbeta_application = generator.generate_application( target_namespace=target_namespace, release=Release(VALID_IMAGE_NAME, VALID_DEPLOY_CONFIG_URL, make_safe_name(APPLICATION_NAME), APPLICATION_NAME, spinnaker_tags, raw_tags)) expected_paasbeta_application = BASE_PAASBETA_APPLICATION expected_paasbeta_application["metadata"][ "namespace"] = expected_namespace assert returned_paasbeta_application.as_dict( ) == expected_paasbeta_application
def test_deploy(client, status): with mock.patch.object(Deployer, 'deploy', return_value=("some-namespace", "app-name", "deploy_id")) as deploy: resp = client.post("/deploy/", data=dumps(VALID_DEPLOY_DATA), content_type="application/json") assert resp.status_code == 201 assert urlparse( resp.location).path == "/status/some-namespace/app-name/deploy_id/" body = loads(resp.data.decode(resp.charset)) assert all(x in body.keys() for x in ("status", "info")) deploy.assert_called_with( DEFAULT_NAMESPACE, Release("test_image", "http://example.com", "example", "example", SPINNAKER_TAGS, RAW_TAGS, {})) status.assert_called_with("some-namespace", "app-name", "deploy_id")