def test_containerapp_compose_create_basic_no_existing_resources( self, resource_group): compose_text = """ services: foo: image: smurawski/printenv:latest """ compose_file_name = f"{self._testMethodName}_compose.yml" write_test_file(compose_file_name, compose_text) self.kwargs.update({ 'environment': self.create_random_name(prefix='containerapp-compose', length=24), 'workspace': self.create_random_name(prefix='containerapp-compose', length=24), 'compose': compose_file_name, }) command_string = 'containerapp compose create' command_string += ' --compose-file-path {compose}' command_string += ' --resource-group {rg}' command_string += ' --environment {environment}' command_string += ' --logs-workspace {workspace}' self.cmd(command_string, checks=[ self.check('[].name', ['foo']), self.check('[] | length(@)', 1), ]) clean_up_test_file(compose_file_name)
def test_containerapp_compose_create_with_resources_from_both_cpus_and_deploy_cpu(self, resource_group): compose_text = """ services: foo: image: mcr.microsoft.com/azuredocs/aks-helloworld:v1 cpus: 0.75 deploy: resources: reservations: cpus: 1.25 expose: - "3000" """ compose_file_name = f"{self._testMethodName}_compose.yml" write_test_file(compose_file_name, compose_text) self.kwargs.update({ 'environment': self.create_random_name(prefix='containerapp-compose', length=24), 'workspace': self.create_random_name(prefix='containerapp-compose', length=24), 'compose': compose_file_name, }) command_string = 'containerapp compose create' command_string += ' --compose-file-path {compose}' command_string += ' --resource-group {rg}' command_string += ' --environment {environment}' command_string += ' --logs-workspace {workspace}' self.cmd(command_string, checks=[ self.check('[?name==`foo`].properties.template.containers[0].resources.cpu', [1.25]), ]) clean_up_test_file(compose_file_name)
def test_containerapp_compose_with_command_list(self, resource_group): compose_text = """ services: foo: image: mcr.microsoft.com/azuredocs/aks-helloworld:v1 command: ["echo", "hello world"] expose: - "5000" """ compose_file_name = f"{self._testMethodName}_compose.yml" write_test_file(compose_file_name, compose_text) self.kwargs.update({ 'environment': self.create_random_name(prefix='containerapp-compose', length=24), 'workspace': self.create_random_name(prefix='containerapp-compose', length=24), 'compose': compose_file_name, }) command_string = 'containerapp compose create' command_string += ' --compose-file-path {compose}' command_string += ' --resource-group {rg}' command_string += ' --environment {environment}' command_string += ' --logs-workspace {workspace}' self.cmd( command_string, checks=[ self.check( '[?name==`foo`].properties.template.containers[0].command[0]', "['echo \"hello world\"']"), ]) clean_up_test_file(compose_file_name)
def test_containerapp_compose_create_with_environment_prompt( self, resource_group): compose_text = """ services: foo: image: mcr.microsoft.com/azuredocs/aks-helloworld:v1 environment: - LOREM= """ compose_file_name = f"{self._testMethodName}_compose.yml" write_test_file(compose_file_name, compose_text) self.kwargs.update({ 'environment': self.create_random_name(prefix='containerapp-compose', length=24), 'workspace': self.create_random_name(prefix='containerapp-compose', length=24), 'compose': compose_file_name, }) command_string = 'containerapp compose create' command_string += ' --compose-file-path {compose}' command_string += ' --resource-group {rg}' command_string += ' --environment {environment}' command_string += ' --logs-workspace {workspace}' # This test fails because prompts are not supported in NoTTY environments self.cmd(command_string, expect_failure=True) clean_up_test_file(compose_file_name)
def test_containerapp_compose_create_with_secrets_and_existing_environment( self, resource_group): compose_text = """ services: foo: image: mcr.microsoft.com/azuredocs/aks-helloworld:v1 environment: database__client: mysql database__connection__host: db database__connection__user: root database__connection__password: example database__connection__database: snafu secrets: - source: my_secret target: redis_secret uid: '103' gid: '103' mode: 0440 secrets: my_secret: file: ./snafu.txt my_other_secret: external: true """ compose_file_name = f"{self._testMethodName}_compose.yml" write_test_file(compose_file_name, compose_text) secrets_file_name = "./snafu.txt" secrets_text = "Lorem Ipsum\n" write_test_file(secrets_file_name, secrets_text) self.kwargs.update({ 'environment': self.create_random_name(prefix='containerapp-compose', length=24), 'workspace': self.create_random_name(prefix='containerapp-compose', length=24), 'compose': compose_file_name, }) command_string = 'containerapp compose create' command_string += ' --compose-file-path {compose}' command_string += ' --resource-group {rg}' command_string += ' --environment {environment}' command_string += ' --logs-workspace {workspace}' self.cmd( command_string, checks=[ self.check( 'length([?name==`foo`].properties.template.containers[0].env[].name)', 6), ]) clean_up_test_file(compose_file_name) clean_up_test_file(secrets_file_name)
def test_containerapp_compose_create_with_secrets(self, resource_group): compose_text = """ services: foo: image: mcr.microsoft.com/azuredocs/aks-helloworld:v1 secrets: - source: my_secret target: redis_secret uid: '103' gid: '103' mode: 0440 secrets: my_secret: file: ./my_secret.txt my_other_secret: external: true """ compose_file_name = f"{self._testMethodName}_compose.yml" write_test_file(compose_file_name, compose_text) secrets_file_name = "./my_secret.txt" secrets_text = "Lorem Ipsum\n" write_test_file(secrets_file_name, secrets_text) self.kwargs.update({ 'environment': self.create_random_name(prefix='containerapp-compose', length=24), 'workspace': self.create_random_name(prefix='containerapp-compose', length=24), 'compose': compose_file_name, }) command_string = 'containerapp compose create' command_string += ' --compose-file-path {compose}' command_string += ' --resource-group {rg}' command_string += ' --environment {environment}' command_string += ' --logs-workspace {workspace}' self.cmd( command_string, checks=[ self.check( '[?name==`foo`].properties.configuration.secrets[0].name', ["redis-secret"]), self.check( '[?name==`foo`].properties.template.containers[0].env[0].name', ["redis-secret"]), self.check( '[?name==`foo`].properties.template.containers[0].env[0].secretRef', ["redis-secret"]) # pylint: disable=C0301 ]) clean_up_test_file(compose_file_name) clean_up_test_file(secrets_file_name)
def test_containerapp_compose_create_with_environment( self, resource_group): compose_text = """ services: foo: image: mcr.microsoft.com/azuredocs/aks-helloworld:v1 environment: - RACK_ENV=development - SHOW=true - BAZ="snafu" """ compose_file_name = f"{self._testMethodName}_compose.yml" write_test_file(compose_file_name, compose_text) self.kwargs.update({ 'environment': self.create_random_name(prefix='containerapp-compose', length=24), 'workspace': self.create_random_name(prefix='containerapp-compose', length=24), 'compose': compose_file_name, }) command_string = 'containerapp compose create' command_string += ' --compose-file-path {compose}' command_string += ' --resource-group {rg}' command_string += ' --environment {environment}' command_string += ' --logs-workspace {workspace}' self.cmd( command_string, checks=[ self.check( '[?name==`foo`].properties.template.containers[0].env[0].name', ["RACK_ENV"]), self.check( '[?name==`foo`].properties.template.containers[0].env[0].value', ["development"]), self.check( '[?name==`foo`].properties.template.containers[0].env[1].name', ["SHOW"]), self.check( '[?name==`foo`].properties.template.containers[0].env[1].value', ["true"]), self.check( '[?name==`foo`].properties.template.containers[0].env[2].name', ["BAZ"]), self.check( '[?name==`foo`].properties.template.containers[0].env[2].value', ['"snafu"']) ]) clean_up_test_file(compose_file_name)
def test_containerapp_compose_create_with_registry_all_args( self, resource_group): compose_text = """ services: foo: image: mcr.microsoft.com/azuredocs/aks-helloworld:v1 ports: 8080:80 """ compose_file_name = f"{self._testMethodName}_compose.yml" write_test_file(compose_file_name, compose_text) self.kwargs.update({ 'environment': self.create_random_name(prefix='containerapp-compose', length=24), 'workspace': self.create_random_name(prefix='containerapp-compose', length=24), 'compose': compose_file_name, 'registry_server': "foobar.azurecr.io", 'registry_user': "******", 'registry_pass': "******", }) command_string = 'containerapp compose create' command_string += ' --compose-file-path {compose}' command_string += ' --resource-group {rg}' command_string += ' --environment {environment}' command_string += ' --logs-workspace {workspace}' command_string += ' --registry-server {registry_server}' command_string += ' --registry-username {registry_user}' command_string += ' --registry-password {registry_pass}' self.cmd( command_string, checks=[ self.check( '[?name==`foo`].properties.configuration.registries[0].server', ["foobar.azurecr.io"]), self.check( '[?name==`foo`].properties.configuration.registries[0].username', ["foobar"]), self.check( '[?name==`foo`].properties.configuration.registries[0].passwordSecretRef', ["foobarazurecrio-foobar"]), # pylint: disable=C0301 ]) clean_up_test_file(compose_file_name)
def test_containerapp_compose_create_with_replicas_global_scale( self, resource_group): compose_text = """ services: foo: image: mcr.microsoft.com/azuredocs/aks-helloworld:v1 ports: 8080:80 scale: 4 deploy: mode: global replicas: 6 """ compose_file_name = f"{self._testMethodName}_compose.yml" write_test_file(compose_file_name, compose_text) self.kwargs.update({ 'environment': self.create_random_name(prefix='containerapp-compose', length=24), 'workspace': self.create_random_name(prefix='containerapp-compose', length=24), 'compose': compose_file_name, }) command_string = 'containerapp compose create' command_string += ' --compose-file-path {compose}' command_string += ' --resource-group {rg}' command_string += ' --environment {environment}' command_string += ' --logs-workspace {workspace}' self.cmd( command_string, checks=[ self.check( '[?name==`foo`].properties.template.scale.minReplicas', [1]), self.check( '[?name==`foo`].properties.template.scale.maxReplicas', [1]), ]) clean_up_test_file(compose_file_name)
def test_containerapp_compose_create_with_secrets_and_existing_environment_conflict( self, resource_group): compose_text = """ services: foo: image: mcr.microsoft.com/azuredocs/aks-helloworld:v1 environment: database--client: mysql secrets: - database__client secrets: database__client: file: ./database__client.txt """ compose_file_name = f"{self._testMethodName}_compose.yml" write_test_file(compose_file_name, compose_text) secrets_file_name = "./database__client.txt" secrets_text = "Lorem Ipsum\n" write_test_file(secrets_file_name, secrets_text) self.kwargs.update({ 'environment': self.create_random_name(prefix='containerapp-compose', length=24), 'workspace': self.create_random_name(prefix='containerapp-compose', length=24), 'compose': compose_file_name, }) command_string = 'containerapp compose create' command_string += ' --compose-file-path {compose}' command_string += ' --resource-group {rg}' command_string += ' --environment {environment}' command_string += ' --logs-workspace {workspace}' # This test fails with duplicate environment variable names self.cmd(command_string, expect_failure=True) clean_up_test_file(compose_file_name) clean_up_test_file(secrets_file_name)
def test_containerapp_compose_create_with_transport_arg( self, resource_group): compose_text = """ services: foo: image: mcr.microsoft.com/azuredocs/aks-helloworld:v1 ports: 8080:80 """ compose_file_name = f"{self._testMethodName}_compose.yml" write_test_file(compose_file_name, compose_text) self.kwargs.update({ 'environment': self.create_random_name(prefix='containerapp-compose', length=24), 'workspace': self.create_random_name(prefix='containerapp-compose', length=24), 'compose': compose_file_name, 'transport': "foo=http2 bar=auto", 'second_transport': "baz=http", }) command_string = 'containerapp compose create' command_string += ' --compose-file-path {compose}' command_string += ' --resource-group {rg}' command_string += ' --environment {environment}' command_string += ' --logs-workspace {workspace}' command_string += ' --transport {transport}' command_string += ' --transport {second_transport}' self.cmd( command_string, checks=[ self.check( '[?name==`foo`].properties.configuration.ingress.transport', ["Http2"]), ]) clean_up_test_file(compose_file_name)
def test_containerapp_compose_create_with_ingress_both( self, resource_group): compose_text = """ services: foo: image: mcr.microsoft.com/azuredocs/aks-helloworld:v1 ports: 4000:3000 expose: - "5000" """ compose_file_name = f"{self._testMethodName}_compose.yml" write_test_file(compose_file_name, compose_text) self.kwargs.update({ 'environment': self.create_random_name(prefix='containerapp-compose', length=24), 'workspace': self.create_random_name(prefix='containerapp-compose', length=24), 'compose': compose_file_name, }) command_string = 'containerapp compose create' command_string += ' --compose-file-path {compose}' command_string += ' --resource-group {rg}' command_string += ' --environment {environment}' command_string += ' --logs-workspace {workspace}' self.cmd( command_string, checks=[ self.check( '[?name==`foo`].properties.configuration.ingress.targetPort', [3000]), self.check( '[?name==`foo`].properties.configuration.ingress.external', [True]), ]) clean_up_test_file(compose_file_name)