def test_required_exec_resource(self, cintf): """A Exec resource that requires others first. """ deployment = cintf.create_deployment('foo') # The run resource waits for now, the "db" service is not available cintf.set_globals('foo', {'Exec': { 'Foo': { 'require': 'db', 'service': 'forum', 'cmd': 'initdb' }}}) assert not get_last_runcfg(cintf, 'once') # Provide the service serving as template; this is not enough # to run the exec resource. cintf.set_service('foo', 'forum', {}) assert not get_last_runcfg(cintf, 'once') # Now, provide the service specified in the requirements. cintf.set_service('foo', 'db', {}) # The Foo resource has now run; it does not care that the service # is held; it only uses the specified service as a template. assert deployment.get_resource('Foo') assert get_last_runcfg(cintf, 'once')
def test_generate(self, cintf): cintf.create_deployment('foo') cintf.set_globals('foo', {'Generate': {'Foo': {}}}) service = cintf.set_service('foo', 'bar', { 'image': 'bar', 'env': {'a': "{Foo}"} }) runcfg_used = get_last_runcfg(cintf) assert len(runcfg_used['env']['a']) == 64 prev_key = runcfg_used['env']['a'] # Run again, get the same result service = cintf.set_service('foo', 'bar', { 'image': 'bar', 'env': {'a': "{Foo}"} }) runcfg_used = get_last_runcfg(cintf) assert runcfg_used['env']['a'] == prev_key
def test_exec_service(self, cintf): deployment = cintf.create_deployment('foo') # The run resource waits for now, the "db" service is not available cintf.set_globals('foo', {'Exec': { 'Foo': { 'service': 'db', 'cmd': 'create name user pass' }}}) assert not get_last_runcfg(cintf, 'once') # Provide the service: make sure it has an provided requirement cintf.set_service('foo', 'db', {'require': 'dep'}) # The Foo resource has now run; it does not care that the service # is held; it only uses the specified service as a template. assert deployment.get_resource('Foo') runcfg = get_last_runcfg(cintf, 'once') assert runcfg['cmd'] == ['create name user pass'] assert runcfg['env']
def test_image_rebuild(self, cintf): """Test insertion of sdutil. """ cintf.create_deployment('foo') # Create a service with a default port, define a dependency service = cintf.set_service( 'foo', 'bar', { 'image': 'bar', 'entrypoint': ['/entry'], 'cmd': ['a-command'], 'sdutil': { 'register': True } }) runcfg_used = get_last_runcfg(cintf) assert runcfg_used['image'] == 'built-id' assert runcfg_used['entrypoint'] == ['/sdutil']
def test_image_rebuild(self, cintf): """Test insertion of sdutil. """ cintf.create_deployment('foo') # Create a service with a default port, define a dependency service = cintf.set_service('foo', 'bar', { 'image': 'bar', 'entrypoint': ['/entry'], 'cmd': ['a-command'], 'sdutil': { 'register': True } }) runcfg_used = get_last_runcfg(cintf) assert runcfg_used['image'] == 'built-id' assert runcfg_used['entrypoint'] == ['/sdutil']
def test_register(self, cintf): """Test sdutil registering. """ cintf.create_deployment('foo') # Create a service with a default port, register it. service = cintf.set_service('foo', 'bar', { 'image': 'bar', 'entrypoint': ['/entry'], 'sdutil': { 'register': True, 'binary': '/my-sdutil' } }) runcfg_used = get_last_runcfg(cintf) assert runcfg_used['entrypoint'] == ['/my-sdutil'] assert runcfg_used['cmd'][:2] == ['exec', '-s'] assert runcfg_used['cmd'][2].startswith('foo:bar:') assert runcfg_used['cmd'][3:5] == ['/entry', 'imgcmd']
def test_register(self, cintf): """Test sdutil registering. """ cintf.create_deployment('foo') # Create a service with a default port, register it. service = cintf.set_service( 'foo', 'bar', { 'image': 'bar', 'entrypoint': ['/entry'], 'sdutil': { 'register': True, 'binary': '/my-sdutil' } }) runcfg_used = get_last_runcfg(cintf) assert runcfg_used['entrypoint'] == ['/my-sdutil'] assert runcfg_used['cmd'][:2] == ['exec', '-s'] assert runcfg_used['cmd'][2].startswith('foo:bar:') assert runcfg_used['cmd'][3:5] == ['/entry', 'imgcmd']
def test_expose(self, cintf): """Test sdutil service exposure. """ cintf.create_deployment('foo') # Create a service with a default port, define a dependency service = cintf.set_service('foo', 'bar', { 'image': 'bar', 'entrypoint': ['/entry'], 'cmd': ['a-command'], 'sdutil': { 'binary': '/my-sdutil', 'expose': { 'dep': 'DEP' } } }) runcfg_used = get_last_runcfg(cintf) assert runcfg_used['entrypoint'] == ['/my-sdutil'] assert runcfg_used['cmd'] == [ 'expose', '-d', 'DEP:foo:dep', '/entry', 'a-command']
def test_variable_insertion(self, cintf): """Test that the database variables are inserted into all of the deployment's containers. """ deployment = cintf.create_deployment('foo') cintf.set_globals('foo', { 'Flynn-Postgres': { 'my-database': { 'in': 'db', 'via': 'db-api', 'expose_as': 'POSTGRES_' } } }) cintf.get_plugin(FlynnPostgresPlugin).set_db_resource( deployment, 'my-database', 'foo', 'bar', 'baz' ) # Deploy a service cintf.set_service('foo', 'a-service', {}) # Have a look at the vars used runcfg = get_last_runcfg(cintf) assert runcfg['env']['POSTGRES_DATABASE'] == 'foo'
def test_variable_insertion(self, cintf): """Test that the database variables are inserted into all of the deployment's containers. """ deployment = cintf.create_deployment('foo') cintf.set_globals( 'foo', { 'Flynn-Postgres': { 'my-database': { 'in': 'db', 'via': 'db-api', 'expose_as': 'POSTGRES_' } } }) cintf.get_plugin(FlynnPostgresPlugin).set_db_resource( deployment, 'my-database', 'foo', 'bar', 'baz') # Deploy a service cintf.set_service('foo', 'a-service', {}) # Have a look at the vars used runcfg = get_last_runcfg(cintf) assert runcfg['env']['POSTGRES_DATABASE'] == 'foo'
def test_expose(self, cintf): """Test sdutil service exposure. """ cintf.create_deployment('foo') # Create a service with a default port, define a dependency service = cintf.set_service( 'foo', 'bar', { 'image': 'bar', 'entrypoint': ['/entry'], 'cmd': ['a-command'], 'sdutil': { 'binary': '/my-sdutil', 'expose': { 'dep': 'DEP' } } }) runcfg_used = get_last_runcfg(cintf) assert runcfg_used['entrypoint'] == ['/my-sdutil'] assert runcfg_used['cmd'] == [ 'expose', '-d', 'DEP:foo:dep', '/entry', 'a-command' ]