def test_attached_preparation_create_kwargs(self): cfg_name = 'app_server' cfg = self.sample_map.get_existing(cfg_name) c_name = 'temp' alias = 'app_server_socket' v_name = 'main.app_server_socket' kwargs = BasePolicy.get_attached_preparation_create_kwargs( self.sample_map, cfg_name, cfg, '__default__', self.sample_client_config, c_name, alias, v_name, include_host_config=True) self.assertDictEqual( kwargs, dict( image=BasePolicy.core_image, command= 'chown -R 2000:2000 /var/lib/app/socket && chmod -R u=rwX,g=rX,o= /var/lib/app/socket', user='******', host_config=create_host_config( volumes_from=[v_name], version=self.client_version, ), network_disabled=True, ))
def test_container_environment_as_dict_kwargs(self): cfg_name = 'web_server' cfg = self.sample_map_2.get_existing(cfg_name) c_name = 'main2.web_server' hc_kwargs = dict(binds={'/new_h': {'bind': '/new_c', 'ro': False}}) kwargs = BasePolicy.get_create_kwargs( self.sample_map, cfg_name, cfg, '__default__', self.sample_client_config, c_name, 'instance1', include_host_config=False, kwargs=dict(host_config=hc_kwargs)) self.assertDictEqual( kwargs, dict( name=c_name, image='registry.example.com/nginx', environment=["DBDATA=/dbdata", "DBDATA1=/dbdata1"], volumes=[u'/etc/nginx'], user=None, hostname='main2.web_server', domainname=None, ports=[80, 443], ))
def test_create_kwargs_with_host_config(self): cfg_name = 'app_server' cfg = self.sample_map.get_existing(cfg_name) c_name = 'main.app_server' hc_kwargs = dict(binds={'/new_h': {'bind': '/new_c', 'ro': False}}) kwargs = BasePolicy.get_create_kwargs(self.sample_map, cfg_name, cfg, '__default__', self.sample_client_config, c_name, 'instance1', include_host_config=True, kwargs=dict(host_config=hc_kwargs)) self.assertDictEqual(kwargs, dict( name=c_name, image='registry.example.com/app', environment=[], volumes=[ '/var/lib/app/config', '/var/lib/app/data' ], user='******', hostname='main.app_server', domainname=None, ports=[8880], host_config=create_host_config( links={}, binds={ '/var/lib/site/config/app1': {'bind': '/var/lib/app/config', 'ro': True}, '/var/lib/site/data/app1': {'bind': '/var/lib/app/data', 'ro': False}, '/new_h': {'bind': '/new_c', 'ro': False}, }, volumes_from=['main.app_log', 'main.app_server_socket'], port_bindings={}, ), ))
def test_create_kwargs_without_host_config(self): cfg_name = 'web_server' cfg = self.sample_map.get_existing(cfg_name) c_name = 'main.web_server' kwargs = BasePolicy.get_create_kwargs(self.sample_map, cfg_name, cfg, '__default__', self.sample_client_config, c_name, None, include_host_config=False, kwargs=dict(ports=[22])) self.assertDictEqual( kwargs, dict( name=c_name, image='registry.example.com/nginx', volumes=['/etc/nginx'], environment=[], user=None, ports=[80, 443, 22], hostname='main.web_server', domainname=None, ))
def test_attached_host_config_kwargs(self): cfg_name = 'app_server' cfg = self.sample_map.get_existing(cfg_name) c_name = 'main.app_server' alias = 'app_server_socket' kwargs = BasePolicy.get_attached_host_config_kwargs(self.sample_map, cfg_name, cfg, '__default__', self.sample_client_config, c_name, alias) self.assertDictEqual(kwargs, dict(container=c_name))
def test_attached_host_config_kwargs(self): cfg_name = 'app_server' cfg = self.sample_map.get_existing(cfg_name) c_name = 'main.app_server' alias = 'app_server_socket' kwargs = BasePolicy.get_attached_host_config_kwargs( self.sample_map, cfg_name, cfg, '__default__', self.sample_client_config, c_name, alias) self.assertDictEqual(kwargs, dict(container=c_name))
def test_remove_kwargs(self): cfg_name = 'web_server' cfg = self.sample_map.get_existing(cfg_name) c_name = 'main.web_server' kwargs = BasePolicy.get_remove_kwargs(self.sample_map, cfg_name, cfg, '__default__', self.sample_client_config, c_name, None) self.assertDictEqual(kwargs, dict(container=c_name, ))
def test_remove_kwargs(self): cfg_name = 'web_server' cfg = self.sample_map.get_existing(cfg_name) c_name = 'main.web_server' kwargs = BasePolicy.get_remove_kwargs(self.sample_map, cfg_name, cfg, '__default__', self.sample_client_config, c_name, None) self.assertDictEqual(kwargs, dict( container=c_name, ))
def stop(clean=False): # We use a "manual approach" here because docker-map's approach is way too complicated for # our needs. NORMAL_CONTAINERS = ['wordpress'] PERSISTENT_CONTAINERS = ['mariadb'] VOLUMES = ['uploads'] client = _get_client() print("Stopping instances...") for name in NORMAL_CONTAINERS + PERSISTENT_CONTAINERS: client.stop(BasePolicy.cname(PROJECT_NAME, name)) for name in NORMAL_CONTAINERS: client.remove_container(BasePolicy.cname(PROJECT_NAME, name)) if clean: print("Cleaning instances...") for name in PERSISTENT_CONTAINERS: client.remove_container(BasePolicy.cname(PROJECT_NAME, name)) for name in VOLUMES: client.remove_container(BasePolicy.aname(PROJECT_NAME, name)) print("Done!")
def setUp(self): self.maxDiff = 2048 self.map_name = 'main' self.sample_map1 = ContainerMap('main', MAP_DATA_1_NEW) self.sample_map2 = ContainerMap('main', MAP_DATA_1) self.client_version1 = CLIENT_DATA_1['version'] self.client_version2 = CLIENT_DATA_2['version'] self.sample_client_config1 = client_config1 = ClientConfiguration(**CLIENT_DATA_1) self.sample_client_config2 = client_config2 = ClientConfiguration(**CLIENT_DATA_2) self.policy = BasePolicy({'main': self.sample_map1}, {'__default__': client_config1, 'legacy': client_config2}) self.runner = DockerClientRunner(self.policy, {})
def test_attached_preparation_host_config_kwargs(self): cfg_name = 'app_server' cfg = self.sample_map.get_existing(cfg_name) c_name = 'temp' alias = 'app_server_socket' v_name = 'main.app_server_socket' kwargs = BasePolicy.get_attached_preparation_host_config_kwargs(self.sample_map, cfg_name, cfg, '__default__', self.sample_client_config, c_name, alias, v_name) self.assertDictEqual(kwargs, dict( container='temp', volumes_from=[v_name], ))
def test_network_setting(self): cfg_name = 'app_extra' cfg = self.sample_map.get_existing(cfg_name) c_name = 'main.app_extra' kwargs = BasePolicy.get_host_config_kwargs(self.sample_map, cfg_name, cfg, '__default__', self.sample_client_config, c_name, None) self.assertDictEqual(kwargs, dict( binds={}, container=c_name, links={}, network_mode='main.app_server.instance1', port_bindings={}, volumes_from=[], ))
def test_attached_preparation_host_config_kwargs(self): cfg_name = 'app_server' cfg = self.sample_map.get_existing(cfg_name) c_name = 'temp' alias = 'app_server_socket' v_name = 'main.app_server_socket' kwargs = BasePolicy.get_attached_preparation_host_config_kwargs( self.sample_map, cfg_name, cfg, '__default__', self.sample_client_config, c_name, alias, v_name) self.assertDictEqual(kwargs, dict( container='temp', volumes_from=[v_name], ))
def test_attached_create_kwargs_without_host_config(self): cfg_name = 'app_server' cfg = self.sample_map.get_existing(cfg_name) c_name = 'main.app_server' alias = 'app_server_socket' kwargs = BasePolicy.get_attached_create_kwargs(self.sample_map, cfg_name, cfg, '__default__', self.sample_client_config, c_name, alias, include_host_config=True) self.assertDictEqual(kwargs, dict( name=c_name, image=BasePolicy.base_image, volumes=['/var/lib/app/socket'], user='******', network_disabled=True, ))
def test_create_kwargs_without_host_config(self): cfg_name = 'web_server' cfg = self.sample_map.get_existing(cfg_name) c_name = 'main.web_server' kwargs = BasePolicy.get_create_kwargs(self.sample_map, cfg_name, cfg, '__default__', self.sample_client_config, c_name, None, include_host_config=False, kwargs=dict(ports=[22])) self.assertDictEqual(kwargs, dict( name=c_name, image='registry.example.com/nginx:latest', volumes=['/etc/nginx'], user=None, ports=[80, 443, 22], hostname='main.web_server', domainname=None, ))
def test_create_kwargs_with_host_config(self): cfg_name = 'app_server' cfg = self.sample_map.get_existing(cfg_name) c_name = 'main.app_server' hc_kwargs = dict(binds={'/new_h': {'bind': '/new_c', 'ro': False}}) kwargs = BasePolicy.get_create_kwargs( self.sample_map, cfg_name, cfg, '__default__', self.sample_client_config, c_name, 'instance1', include_host_config=True, kwargs=dict(host_config=hc_kwargs)) self.assertDictEqual( kwargs, dict( name=c_name, image='registry.example.com/app:custom', volumes=['/var/lib/app/config', '/var/lib/app/data'], user='******', hostname='main.app_server', domainname=None, ports=[8880], host_config=create_host_config( links={}, binds={ '/var/lib/site/config/app1': { 'bind': '/var/lib/app/config', 'ro': True }, '/var/lib/site/data/app1': { 'bind': '/var/lib/app/data', 'ro': False }, '/new_h': { 'bind': '/new_c', 'ro': False }, }, volumes_from=['main.app_log', 'main.app_server_socket'], port_bindings={}, version=self.client_version, ), ))
def test_network_setting(self): cfg_name = 'app_extra' cfg = self.sample_map.get_existing(cfg_name) c_name = 'main.app_extra' kwargs = BasePolicy.get_host_config_kwargs(self.sample_map, cfg_name, cfg, '__default__', self.sample_client_config, c_name, None) self.assertDictEqual( kwargs, dict( binds={}, container=c_name, links={}, network_mode='main.app_server.instance1', port_bindings={}, volumes_from=[], ))
def test_attached_preparation_create_kwargs(self): cfg_name = 'app_server' cfg = self.sample_map.get_existing(cfg_name) c_name = 'temp' alias = 'app_server_socket' v_name = 'main.app_server_socket' kwargs = BasePolicy.get_attached_preparation_create_kwargs(self.sample_map, cfg_name, cfg, '__default__', self.sample_client_config, c_name, alias, v_name, include_host_config=True) self.assertDictEqual(kwargs, dict( image=BasePolicy.core_image, command='chown -R 2000:2000 /var/lib/app/socket && chmod -R u=rwX,g=rX,o= /var/lib/app/socket', user='******', host_config=create_host_config( volumes_from=[v_name], ), network_disabled=True, ))
def test_host_config_kwargs(self): cfg_name = 'web_server' cfg = self.sample_map.get_existing(cfg_name) c_name = 'main.web_server' kwargs = BasePolicy.get_host_config_kwargs(self.sample_map, cfg_name, cfg, '__default__', self.sample_client_config, c_name, None, kwargs=dict(binds={'/new_h': {'bind': '/new_c', 'ro': False}})) self.assertDictEqual(kwargs, dict( container=c_name, links={ 'main.app_server.instance1': 'app_server.instance1', 'main.app_server.instance2': 'app_server.instance2', }, binds={ '/var/lib/site/config/nginx': {'bind': '/etc/nginx', 'ro': True}, '/new_h': {'bind': '/new_c', 'ro': False}, }, volumes_from=['main.app_server_socket', 'main.web_log'], port_bindings={80: 80, 443: 443}, ))
def test_host_config_kwargs(self): cfg_name = 'web_server' cfg = self.sample_map.get_existing(cfg_name) c_name = 'main.web_server' kwargs = BasePolicy.get_host_config_kwargs( self.sample_map, cfg_name, cfg, '__default__', self.sample_client_config, c_name, None, kwargs=dict(binds={'/new_h': { 'bind': '/new_c', 'ro': False }})) self.assertDictEqual( kwargs, dict( container=c_name, links=[ ('main.app_server.instance1', 'app_server.instance1'), ('main.app_server.instance2', 'app_server.instance2'), ], binds={ '/var/lib/site/config/nginx': { 'bind': '/etc/nginx', 'ro': True }, '/new_h': { 'bind': '/new_c', 'ro': False }, }, volumes_from=['main.app_server_socket', 'main.web_log'], port_bindings={ 80: [80], 443: [443] }, version=self.client_version, ))
def test_container_environment_as_dict_kwargs(self): cfg_name = 'web_server' cfg = self.sample_map_2.get_existing(cfg_name) c_name = 'main2.web_server' hc_kwargs = dict(binds={'/new_h': {'bind': '/new_c', 'ro': False}}) kwargs = BasePolicy.get_create_kwargs(self.sample_map, cfg_name, cfg, '__default__', self.sample_client_config, c_name, 'instance1', include_host_config=False, kwargs=dict(host_config=hc_kwargs)) self.assertDictEqual(kwargs, dict( name=c_name, image='registry.example.com/nginx', environment=[ "DBDATA=/dbdata", "DBDATA1=/dbdata1" ], volumes=[u'/etc/nginx'], user=None, hostname='main2.web_server', domainname=None, ports=[80,443], ))
def test_attached_create_kwargs_without_host_config(self): cfg_name = 'app_server' cfg = self.sample_map.get_existing(cfg_name) c_name = 'main.app_server' alias = 'app_server_socket' kwargs = BasePolicy.get_attached_create_kwargs( self.sample_map, cfg_name, cfg, '__default__', self.sample_client_config, c_name, alias, include_host_config=False) self.assertDictEqual( kwargs, dict( name=c_name, image=BasePolicy.base_image, volumes=['/var/lib/app/socket'], user='******', network_disabled=True, ))