Example #1
0
 def assert_b(v, m=None, i=None):
     six.assertCountEqual(self, InputConfigIdList(v, map_name=m, instances=i),
                          [InputConfigId(ItemType.CONTAINER, 'm', 'c', ('i', )),
                           InputConfigId(ItemType.CONTAINER, 'm', 'd', ('i', )),
                           InputConfigId(ItemType.CONTAINER, 'n', 'e', ('i', 'j'))])
     six.assertCountEqual(self, get_map_config_ids(v, maps, default_map_name=m, default_instances=i),
                          [MapConfigId(ItemType.CONTAINER, 'm', 'c', 'i'),
                           MapConfigId(ItemType.CONTAINER, 'm', 'd', 'i'),
                           MapConfigId(ItemType.CONTAINER, 'n', 'e', 'i'),
                           MapConfigId(ItemType.CONTAINER, 'n', 'e', 'j')])
 def test_create_kwargs_with_host_config(self):
     cfg_name = 'app_server'
     cfg = self.sample_map2.get_existing(cfg_name)
     cfg_id = MapConfigId(ItemType.CONTAINER, 'main', cfg_name, 'instance1')
     c_name = 'main.app_server'
     config = ActionConfig('legacy', cfg_id, self.sample_client_config2, None, self.sample_map2, cfg)
     hc_kwargs = dict(binds=['/new_h:/new_c:rw'])
     kwargs = self.runner.get_container_create_kwargs(config, c_name, 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-legacy',
         domainname=None,
         ports=[8880],
         host_config=HostConfig(
             links={},
             binds=[
                 '/var/lib/site/config/app1:/var/lib/app/config:ro',
                 '/var/lib/site/data/app1:/var/lib/app/data:rw',
                 '/new_h:/new_c:rw',
             ],
             volumes_from=['main.app_log', 'main.app_server_socket'],
             port_bindings={},
             version=self.client_version2,
         ),
     ))
 def test_attached_host_config_kwargs(self):
     cfg_name = 'app_server'
     cfg = self.sample_map2.get_existing(cfg_name)
     cfg_id = MapConfigId(ItemType.VOLUME, 'main', cfg_name, 'app_server_socket')
     c_name = 'main.app_server'
     config = ActionConfig('legacy', cfg_id, self.sample_client_config2, None, self.sample_map2, cfg)
     kwargs = self.runner.get_attached_container_host_config_kwargs(config, c_name)
     self.assertDictEqual(kwargs, dict(container=c_name))
 def test_remove_kwargs(self):
     cfg_name = 'web_server'
     cfg = self.sample_map1.get_existing(cfg_name)
     cfg_id = MapConfigId(ItemType.CONTAINER, 'main', cfg_name)
     c_name = 'main.web_server'
     config = ActionConfig('__default__', cfg_id, self.sample_client_config1, None, self.sample_map1, cfg)
     kwargs = self.runner.get_container_remove_kwargs(config, c_name)
     self.assertDictEqual(kwargs, dict(
         container=c_name,
     ))
 def test_attached_create_kwargs_without_host_config(self):
     cfg_name = 'app_server'
     cfg = self.sample_map2.get_existing(cfg_name)
     cfg_id = MapConfigId(ItemType.VOLUME, 'main', cfg_name, 'app_server_socket')
     c_name = 'main.app_server'
     config = ActionConfig('legacy', cfg_id, self.sample_client_config2, None, self.sample_map2, cfg)
     kwargs = self.runner.get_attached_container_create_kwargs(config, c_name)
     self.assertDictEqual(kwargs, dict(
         name=c_name,
         image=BasePolicy.base_image,
         volumes=['/var/lib/app/socket'],
         user='******',
         network_disabled=True,
     ))
 def test_update_kwargs(self):
     cfg_name = 'web_server'
     cfg = self.sample_map1.get_existing(cfg_name)
     cfg_id = MapConfigId(ItemType.CONTAINER, 'main', cfg_name)
     c_name = 'main.web_server'
     config = ActionConfig('__default__', cfg_id, self.sample_client_config1, None, self.sample_map1, cfg)
     kwargs = self.runner.get_container_update_kwargs(config, c_name, {
         'mem_limit': '2g',
         'cpu_shares': 512,
     })
     self.assertDictEqual(kwargs, dict(
         container=c_name,
         mem_limit='2g',
         cpu_shares=512,
     ))
 def test_network_setting(self):
     cfg_name = 'app_extra'
     cfg = self.sample_map2.get_existing(cfg_name)
     cfg_id = MapConfigId(ItemType.CONTAINER, 'main', cfg_name)
     c_name = 'main.app_extra'
     config = ActionConfig('__default__', cfg_id, self.sample_client_config2, None, self.sample_map2, cfg)
     kwargs = self.runner.get_container_host_config_kwargs(config, c_name)
     self.assertDictEqual(kwargs, dict(
         binds=[],
         container=c_name,
         links=[],
         network_mode='container:main.app_server.instance1',
         port_bindings={},
         volumes_from=[],
     ))
 def test_create_kwargs_without_host_config(self):
     cfg_name = 'web_server'
     cfg = self.sample_map1.get_existing(cfg_name)
     cfg_id = MapConfigId(ItemType.CONTAINER, 'main', cfg_name)
     c_name = 'main.web_server'
     self.sample_client_config2.features['host_config'] = False
     config = ActionConfig('legacy', cfg_id, self.sample_client_config2, None, self.sample_map2, cfg)
     kwargs = self.runner.get_container_create_kwargs(config, c_name, 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-legacy',
         domainname=None,
     ))
 def test_attached_preparation_create_kwargs(self):
     cfg_name = 'app_server'
     cfg = self.sample_map2.get_existing(cfg_name)
     cfg_id = MapConfigId(ItemType.VOLUME, 'main', cfg_name, 'app_server_socket')
     v_name = 'main.app_server_socket'
     config = ActionConfig('legacy', cfg_id, self.sample_client_config2, None, self.sample_map2, cfg)
     kwargs = self.runner.get_attached_preparation_create_kwargs(config, v_name, 'app_server_socket')
     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=HostConfig(
             volumes_from=[v_name],
             version=self.client_version2,
         ),
         network_disabled=True,
     ))
Example #10
0
 def test_create_kwargs_with_host_config_and_volumes_networks(self):
     cfg_name = 'app_server'
     cfg = self.sample_map1.get_existing(cfg_name)
     cfg_id = MapConfigId(ItemType.CONTAINER, 'main', cfg_name, 'instance1')
     c_name = 'main.app_server'
     config = ActionConfig('__default__', cfg_id, self.sample_client_config1, None, self.sample_map1, cfg)
     hc_kwargs = dict(binds=['/new_h:/new_c:rw'])
     kwargs = self.runner.get_container_create_kwargs(config, c_name, 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',
             '/var/lib/app/log',
             '/var/lib/app/socket',
         ],
         user='******',
         hostname='main-app-server',
         domainname=None,
         ports=[8880],
         networking_config={'EndpointsConfig': {'main.app': {}}},
         stop_timeout=10,
         healthcheck={
             'test': ['CMD', 'curl', 'http://localhost/'],
             'interval': 60000000000,
             'timeout': 1000000000,
             'retries': 3,
             'start_period': 5000000000,
         },
         host_config=HostConfig(
             links={},
             binds=[
                 '/var/lib/site/config/app1:/var/lib/app/config:ro',
                 '/var/lib/site/data/app1:/var/lib/app/data:rw',
                 'main.app_log:/var/lib/app/log:rw',
                 'main.app_server_socket:/var/lib/app/socket:rw',
                 '/new_h:/new_c:rw',
             ],
             volumes_from=[],
             port_bindings={},
             version=self.client_version1,
         ),
         stop_signal='SIGTERM',
     ))
Example #11
0
 def test_attached_preparation_create_kwargs_with_volumes(self):
     cfg_name = 'app_server'
     cfg = self.sample_map1.get_existing(cfg_name)
     cfg_id = MapConfigId(ItemType.VOLUME, 'main', cfg_name, 'app_server_socket')
     v_name = 'main.app_server_socket'
     config = ActionConfig('__default__', cfg_id, self.sample_client_config1, None, self.sample_map1, cfg)
     kwargs = self.runner.get_attached_preparation_create_kwargs(config, v_name, 'app_server_socket')
     self.assertDictEqual(kwargs, dict(
         image=BasePolicy.core_image,
         command='chown -R 2000:2000 /volume-tmp && chmod -R u=rwX,g=rX,o= /volume-tmp',
         user='******',
         volumes=['/volume-tmp'],
         host_config=HostConfig(
             binds=['main.app_server_socket:/volume-tmp'],
             version=self.client_version1,
         ),
         network_disabled=True,
     ))
Example #12
0
 def test_host_config_kwargs(self):
     cfg_name = 'web_server'
     cfg = self.sample_map2.get_existing(cfg_name)
     cfg_id = MapConfigId(ItemType.CONTAINER, 'main', cfg_name)
     c_name = 'main.web_server'
     config = ActionConfig('legacy', cfg_id, self.sample_client_config2, None, self.sample_map2, cfg)
     kwargs = self.runner.get_container_host_config_kwargs(config, c_name,
                                                           kwargs=dict(binds=['/new_h:/new_c:rw']))
     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:/etc/nginx:ro',
             '/new_h:/new_c:rw',
         ],
         volumes_from=['main.app_server_socket', 'main.web_log'],
         port_bindings={80: [80], 443: [443]},
     ))
Example #13
0
 def test_get_map_config_ids_all_alias(self):
     map_m = ContainerMap('m', c1=dict(), c2=dict(), c3=dict(), groups=dict(default=['c3']))
     map_n = ContainerMap('n', c1=dict(), c3=dict(), groups=dict(default=['c3']))
     maps = {'m': map_m, 'n': map_n}
     six.assertCountEqual(self, get_map_config_ids('m.__all__', maps),
                          [MapConfigId(ItemType.CONTAINER, 'm', 'c1'),
                           MapConfigId(ItemType.CONTAINER, 'm', 'c2'),
                           MapConfigId(ItemType.CONTAINER, 'm', 'c3')])
     six.assertCountEqual(self, get_map_config_ids('__all__.__all__', maps),
                          [MapConfigId(ItemType.CONTAINER, 'm', 'c1'),
                           MapConfigId(ItemType.CONTAINER, 'm', 'c2'),
                           MapConfigId(ItemType.CONTAINER, 'm', 'c3'),
                           MapConfigId(ItemType.CONTAINER, 'n', 'c1'),
                           MapConfigId(ItemType.CONTAINER, 'n', 'c3')])
     six.assertCountEqual(self, get_map_config_ids('__all__.c1',maps),
                          [MapConfigId(ItemType.CONTAINER, 'm', 'c1'),
                           MapConfigId(ItemType.CONTAINER, 'n', 'c1')])
     six.assertCountEqual(self, get_map_config_ids('__all__.default', maps),
                          [MapConfigId(ItemType.CONTAINER, 'm', 'c3'),
                           MapConfigId(ItemType.CONTAINER, 'n', 'c3')])
Example #14
0
 def assert_d(v, m=None, i=None):
     six.assertCountEqual(self, expand_groups(InputConfigIdList(v, map_name=m, instances=i), maps),
                          [InputConfigId(ItemType.NETWORK, 'n', 'nn1')])
     six.assertCountEqual(self, get_map_config_ids(v, maps, default_map_name=m, default_instances=i),
                          [MapConfigId(ItemType.NETWORK, 'n', 'nn1')])
Example #15
0
 def assert_a(v, m=None, i=None):
     self.assertEqual(InputConfigIdList(v, map_name=m, instances=i),
                      [InputConfigId(ItemType.CONTAINER, 'm', 'c')])
     self.assertEqual(get_map_config_ids(v, maps, default_map_name=m, default_instances=i),
                      [MapConfigId(ItemType.CONTAINER, 'm', 'c', 'i')])