Ejemplo n.º 1
0
 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={},
         ),
     ))
Ejemplo n.º 2
0
 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],
         ))
Ejemplo n.º 3
0
 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,
         ))
Ejemplo n.º 4
0
 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,
     ))
Ejemplo n.º 5
0
 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,
             ),
         ))
Ejemplo n.º 6
0
    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],

        ))