Esempio n. 1
0
 def test_single_config(self):
     cfg = self.sample_map.get_existing('abstract_config')
     self.assertTrue(cfg.abstract)
     self.assertEqual(cfg.image, 'server')
     self.assertEqual(cfg.binds, [SharedVolume('app_config', True)])
     self.assertEqual(cfg.uses, [SharedVolume('redis.redis_socket', False)])
     self.assertEqual(cfg.attaches, [SharedVolume('app_log')])
     self.assertEqual(cfg.user, 'app_user')
     self.assertEqual(cfg.permissions, 'u=rwX,g=rX,o=')
Esempio n. 2
0
    def test_get_shared_volume(self):
        assert_a = lambda a: self.assertEqual(get_shared_volume(a), SharedVolume('a', False))
        assert_b = lambda b: self.assertEqual(get_shared_volume(b), SharedVolume('b', True))

        assert_a(SharedVolume('a', False))
        assert_a('a')
        assert_a(('a', ))
        assert_b(('b', 'true'))
        assert_b({'b': 'true'})
Esempio n. 3
0
    def test_get_shared_volumes(self):
        assert_a = lambda a: self.assertEqual(get_shared_volumes(a), [SharedVolume('a', False)])
        assert_b = lambda b: self.assertItemsEqual(get_shared_volumes(b), [SharedVolume('a', False),
                                                                           SharedVolume('b', True)])

        assert_a(SharedVolume('a', False))
        assert_a('a')
        assert_a(('a', ))
        assert_a({'a': False})
        assert_b(['a', ('b', 'true')])
        assert_b({'a': False, 'b': 'true'})
Esempio n. 4
0
 def test_merge_with_config_lists_only(self):
     cfg = self.sample_map.get_existing('abstract_config')
     merge_cfg = self.sample_map.get_existing('server')
     cfg.merge(merge_cfg, lists_only=True)
     self.assertEqual(cfg.binds, [SharedVolume('app_config', True), SharedVolume('app_data', False)])
     self.assertEqual(cfg.uses, [SharedVolume('redis.redis_socket', False)])
     self.assertEqual(cfg.attaches, ['app_log', 'server_log'])
     self.assertEqual(cfg.user, 'app_user')
     self.assertEqual(cfg.exposes, [PortBinding(8443, 8443, 'private')])
     self.assertIs(cfg.create_options, NotSet)
     self.assertIs(cfg.host_config, NotSet)
Esempio n. 5
0
 def test_merge_with_config_lists_only(self):
     cfg = self.sample_map.get_existing('abstract_config').copy()
     merge_cfg = self.sample_map.get_existing('server')
     cfg.merge(merge_cfg, lists_only=True)
     self.assertEqual(cfg.binds, [SharedVolume('app_config', True), SharedVolume('app_data', False)])
     self.assertEqual(cfg.uses, [SharedVolume('redis.redis_socket', False)])
     self.assertEqual(cfg.attaches, [SharedVolume('app_log'), SharedVolume('server_log')])
     self.assertEqual(cfg.user, 'app_user')
     self.assertEqual(cfg.exposes, [PortBinding(8443, 8443, 'private', False)])
     self.assertEqual(cfg.links, [ContainerLink('svc', 'svc_alias1'), ContainerLink('svc', 'svc_alias2')])
     self.assertDictEqual(cfg.create_options, {})
     self.assertDictEqual(cfg.host_config, {})
Esempio n. 6
0
 def test_merge_with_dict_lists_only(self):
     cfg = self.sample_map.get_existing('abstract_config')
     merge_dict = MAP_DATA_2['containers']['server']
     cfg.merge(merge_dict, lists_only=True)
     self.assertEqual(cfg.binds, [SharedVolume('app_config', True), SharedVolume('app_data', False)])
     self.assertEqual(cfg.uses, [SharedVolume('redis.redis_socket', False)])
     self.assertEqual(cfg.attaches, ['app_log', 'server_log'])
     self.assertEqual(cfg.user, 'app_user')
     self.assertEqual(cfg.exposes, [PortBinding(8443, 8443, 'private', False)])
     self.assertEqual(cfg.links, [ContainerLink('svc', 'svc_alias1'), ContainerLink('svc', 'svc_alias2')])
     self.assertIs(cfg.create_options, NotSet)
     self.assertIs(cfg.host_config, NotSet)
Esempio n. 7
0
    def test_get_attached_volume(self):
        l = AttachedVolumeList()
        assert_a = lambda a: self.assertEqual(l.get_type_item(a), SharedVolume('a', False))
        assert_c = lambda c: self.assertEqual(l.get_type_item(c), UsedVolume('c', 'p1', False))

        assert_a(SharedVolume('a', False))
        assert_a('a')
        assert_a(('a', ))
        assert_a({'name': 'a'})
        assert_c(UsedVolume('c', 'p1'))
        assert_c(('c', 'p1'))
        assert_c({'c': 'p1'})
        assert_c({'name': 'c', 'path': 'p1'})
Esempio n. 8
0
    def test_get_shared_host_volumes(self):
        assert_a = lambda a: self.assertEqual(SharedHostVolumesList(a), [SharedVolume('a', False)])
        assert_b = lambda b: six.assertCountEqual(self, SharedHostVolumesList(b), [SharedVolume('a', False),
                                                                                   SharedVolume('b', True),
                                                                                   HostVolume('c', 'ch', False),
                                                                                   HostVolume('d', 'dh', True)])

        assert_a('a')
        assert_a([('a', )])
        assert_a((['a', False], ))
        assert_b([['a'], SharedVolume('b', True), ('c', 'ch'), ('d', 'dh', 'ro')])
        assert_b(['a', ('b', 'ro'), ('c', ['ch']), ('d', 'dh', True)])
        assert_b({'a': False, 'b': 'ro', 'c': 'ch', 'd': ('dh', True)})
Esempio n. 9
0
    def test_get_attached_volumes(self):
        assert_a = lambda a: self.assertEqual(AttachedVolumeList(a), [SharedVolume('a', False)])
        assert_b = lambda b: six.assertCountEqual(self, AttachedVolumeList(b), [SharedVolume('a', False),
                                                                                SharedVolume('b', False),
                                                                                UsedVolume('c', 'p1', False)])

        assert_a(SharedVolume('a', False))
        assert_a('a')
        assert_a(('a', ))
        assert_a([{'name': 'a'}])
        assert_b(['a', ('b', False), {'c': 'p1'}])
        assert_b({'a': False, 'b': None, 'c': 'p1'})
        assert_b({'a': False, 'b': None, 'c': 'p1'})
        assert_b((SharedVolume('a'), {'name': 'b', 'readonly': False}, {'name': 'c', 'path': 'p1'}))
Esempio n. 10
0
 def test_extended_config(self):
     cfg = self.ext_main.get_existing('server')
     self.assertEqual(cfg.binds, [SharedVolume('app_config', True), SharedVolume('app_data', False)])
     self.assertEqual(cfg.uses, [SharedVolume('redis.redis_socket', False)])
     self.assertEqual(cfg.attaches, ['app_log', 'server_log'])
     self.assertEqual(cfg.user, 'server_user')
     self.assertEqual(cfg.exposes, [PortBinding(8443, 8443, 'private')])
     self.assertEqual(cfg.create_options, {
         'mem_limit': '1g',
         'cpu_shares': 15,
     })
     self.assertEqual(cfg.host_config, {
         'restart_policy': {
             'MaximumRetryCount': 3,
             'Name': 'always',
         },
     })
Esempio n. 11
0
 def test_get_persistent(self):
     attached_items, persistent_items = self.ext_main.get_persistent_items()
     six.assertCountEqual(self, attached_items, [('worker', SharedVolume('app_log')),
                                                 ('server', SharedVolume('app_log')),
                                                 ('server', SharedVolume('server_log')),
                                                 ('server2', SharedVolume('app_log')),
                                                 ('server2', SharedVolume('server_log')),
                                                 ('redis', SharedVolume('redis_socket')),
                                                 ('redis', SharedVolume('redis_log')),
                                                 ('worker_q2', SharedVolume('app_log'))])
     six.assertCountEqual(self, persistent_items, [('persistent_one', None)])
Esempio n. 12
0
 def test_merge_with_dict(self):
     cfg = self.sample_map.get_existing('abstract_config')
     merge_dict = MAP_DATA_2['containers']['server']
     cfg.merge(merge_dict)
     self.assertEqual(cfg.binds, [SharedVolume('app_config', True), SharedVolume('app_data', False)])
     self.assertEqual(cfg.uses, [SharedVolume('redis.redis_socket', False)])
     self.assertEqual(cfg.attaches, ['app_log', 'server_log'])
     self.assertEqual(cfg.user, 'server_user')
     self.assertEqual(cfg.exposes, [PortBinding(8443, 8443, 'private')])
     self.assertEqual(cfg.create_options, {
         'mem_limit': '1g',
         'cpu_shares': 15,
     })
     self.assertEqual(cfg.host_config, {
         'restart_policy': {
             'MaximumRetryCount': 3,
             'Name': 'always',
         },
     })
Esempio n. 13
0
 def test_merge_with_config(self):
     cfg = self.sample_map.get_existing('abstract_config').copy()
     merge_cfg = self.sample_map.get_existing('server')
     cfg.merge(merge_cfg)
     self.assertEqual(cfg.binds, [SharedVolume('app_config', True), SharedVolume('app_data', False)])
     self.assertEqual(cfg.uses, [SharedVolume('redis.redis_socket', False)])
     self.assertEqual(cfg.attaches, [SharedVolume('app_log'), SharedVolume('server_log')])
     self.assertEqual(cfg.user, 'server_user')
     self.assertEqual(cfg.exposes, [PortBinding(8443, 8443, 'private', False)])
     self.assertEqual(cfg.links, [ContainerLink('svc', 'svc_alias1'), ContainerLink('svc', 'svc_alias2')])
     self.assertEqual(cfg.create_options, {
         'mem_limit': '1g',
         'cpu_shares': 15,
     })
     self.assertEqual(cfg.host_config, {
         'restart_policy': {
             'MaximumRetryCount': 3,
             'Name': 'always',
         },
     })
Esempio n. 14
0
    def test_get_shared_host_volume(self):
        assert_a = lambda a: self.assertEqual(get_shared_host_volume(a), SharedVolume('a', False))
        assert_b = lambda b: self.assertEqual(get_shared_host_volume(b), SharedVolume('b', True))
        assert_c = lambda c: self.assertEqual(get_shared_host_volume(c), SharedVolume(('c', 'ch'), False))
        assert_d = lambda d: self.assertEqual(get_shared_host_volume(d), SharedVolume(('d', 'dh'), True))

        assert_a('a')
        assert_a(('a', ))
        assert_a(['a', False])
        assert_b(SharedVolume('b', True))
        assert_b(('b', 'ro'))
        assert_b({'b': 'ro'})
        assert_c(('c', 'ch'))
        assert_c(('c', 'ch', False))
        assert_c(('c', ['ch']))
        assert_c(('c', ('ch', 'rw')))
        assert_c({'c': 'ch'})
        assert_c({'c': ('ch', )})
        assert_d(('d', 'dh', 'ro'))
        assert_d({'d': ('dh', True)})
Esempio n. 15
0
    def test_get_shared_host_volume(self):
        l = SharedHostVolumesList()
        assert_a = lambda a: self.assertEqual(l.get_type_item(a), SharedVolume('a', False))
        assert_b = lambda b: self.assertEqual(l.get_type_item(b), SharedVolume('b', True))
        assert_c = lambda c: self.assertEqual(l.get_type_item(c), HostVolume('c', 'ch', False))
        assert_d = lambda d: self.assertEqual(l.get_type_item(d), HostVolume('d', 'dh', True))

        assert_a('a')
        assert_a(('a', ))
        assert_a(['a', False])
        assert_b(SharedVolume('b', True))
        assert_b(('b', 'ro'))
        assert_b({'b': 'ro'})
        assert_c(('c', 'ch'))
        assert_c(('c', 'ch', False))
        assert_c(('c', ['ch']))
        assert_c(('c', ('ch', 'rw')))
        assert_c({'c': 'ch'})
        assert_c({'c': ('ch', )})
        assert_d(('d', 'dh', 'ro'))
        assert_d({'d': ('dh', True)})
Esempio n. 16
0
 def test_more_extended_config(self):
     cfg1_1 = self.sample_map.get_existing('worker')
     cfg1 = self.sample_map.get_extended(cfg1_1)
     self.assertEqual(cfg1.binds, [SharedVolume('app_config', True), SharedVolume('app_data', False)])
     self.assertEqual(cfg1.uses, [SharedVolume('redis.redis_socket', False)])
     self.assertEqual(cfg1.attaches, [SharedVolume('app_log')])
     self.assertEqual(cfg1.user, 'app_user')
     self.assertEqual(cfg1.create_options, {
         'mem_limit': '2g',
         'cpu_shares': 10,
         'entrypoint': 'celery',
         'command': 'worker -A MyApp -Q queue1,queue2',
     })
     self.assertEqual(cfg1.host_config, {
         'restart_policy': {
             'MaximumRetryCount': 0,
             'Name': 'always',
         },
     })
     cfg2 = self.ext_main.get_existing('worker_q2')
     self.assertEqual(cfg2.binds, [SharedVolume('app_config', True), SharedVolume('app_data', False)])
     self.assertEqual(cfg2.uses, [SharedVolume('redis.redis_socket', False)])
     self.assertEqual(cfg2.attaches, [SharedVolume('app_log')])
     self.assertEqual(cfg2.user, 'app_user')
     self.assertEqual(cfg2.create_options, {
         'mem_limit': '1g',
         'cpu_shares': 30,
         'entrypoint': 'celery',
         'command': 'worker -A MyApp -Q queue2',
     })
     self.assertEqual(cfg2.host_config, {
         'restart_policy': {
             'MaximumRetryCount': 0,
             'Name': 'always',
         },
     })