示例#1
0
 def test_start_with_mapping_devices(self):
     t = template_format.parse(template)
     self.stack = utils.parse_stack(t)
     definition = self.stack.t.resource_definitions(self.stack)['Blog']
     definition['Properties']['devices'] = ([{
         'path_on_host': '/dev/sda',
         'path_in_container': '/dev/xvdc',
         'permissions': 'r'
     }, {
         'path_on_host': '/dev/mapper/a_bc-d',
         'path_in_container': '/dev/xvdd',
         'permissions': 'rw'
     }])
     my_resource = docker_container.DockerContainer('Blog', definition,
                                                    self.stack)
     get_client_mock = self.patchobject(my_resource, 'get_client')
     get_client_mock.return_value = fakeclient.FakeDockerClient()
     self.assertIsNone(my_resource.validate())
     scheduler.TaskRunner(my_resource.create)()
     self.assertEqual((my_resource.CREATE, my_resource.COMPLETE),
                      my_resource.state)
     client = my_resource.get_client()
     self.assertEqual(['samalba/wordpress'], client.pulled_images)
     self.assertEqual(
         ['/dev/sda:/dev/xvdc:r', '/dev/mapper/a_bc-d:/dev/xvdd:rw'],
         client.container_start[0]['devices'])
示例#2
0
 def test_start_with_bindings_and_links(self):
     t = template_format.parse(template)
     self.stack = utils.parse_stack(t)
     definition = self.stack.t.resource_definitions(self.stack)['Blog']
     definition['Properties']['port_bindings'] = {
         '80/tcp': [{
             'HostPort': '80'
         }]
     }
     definition['Properties']['links'] = {'db': 'mysql'}
     resource = docker_container.DockerContainer('Blog', definition,
                                                 self.stack)
     self.m.StubOutWithMock(resource, 'get_client')
     resource.get_client().MultipleTimes().AndReturn(
         fakeclient.FakeDockerClient())
     self.assertIsNone(resource.validate())
     self.m.ReplayAll()
     scheduler.TaskRunner(resource.create)()
     self.assertEqual((resource.CREATE, resource.COMPLETE), resource.state)
     client = resource.get_client()
     self.assertEqual(['samalba/wordpress'], client.pulled_images)
     self.assertEqual({'db': 'mysql'}, client.container_start[0]['links'])
     self.assertEqual({'80/tcp': [{
         'HostPort': '80'
     }]}, client.container_start[0]['port_bindings'])
示例#3
0
 def create_container(self, resource_name):
     t = template_format.parse(template)
     self.stack = utils.parse_stack(t)
     resource = docker_container.DockerContainer(
         resource_name,
         self.stack.t.resource_definitions(self.stack)[resource_name],
         self.stack)
     self.m.StubOutWithMock(resource, 'get_client')
     resource.get_client().MultipleTimes().AndReturn(
         fakeclient.FakeDockerClient())
     self.assertIsNone(resource.validate())
     self.m.ReplayAll()
     scheduler.TaskRunner(resource.create)()
     self.assertEqual((resource.CREATE, resource.COMPLETE), resource.state)
     return resource
示例#4
0
 def test_create_with_cpu_set(self):
     t = template_format.parse(template)
     self.stack = utils.parse_stack(t)
     definition = self.stack.t.resource_definitions(self.stack)['Blog']
     definition['Properties']['cpu_set'] = '0-8,16-24,28'
     my_resource = docker_container.DockerContainer('Blog', definition,
                                                    self.stack)
     get_client_mock = self.patchobject(my_resource, 'get_client')
     get_client_mock.return_value = fakeclient.FakeDockerClient()
     self.assertIsNone(my_resource.validate())
     scheduler.TaskRunner(my_resource.create)()
     self.assertEqual((my_resource.CREATE, my_resource.COMPLETE),
                      my_resource.state)
     client = my_resource.get_client()
     self.assertEqual(['samalba/wordpress'], client.pulled_images)
     self.assertEqual('0-8,16-24,28', client.container_create[0]['cpuset'])
示例#5
0
 def test_start_with_read_only(self):
     t = template_format.parse(template)
     self.stack = utils.parse_stack(t)
     definition = self.stack.t.resource_definitions(self.stack)['Blog']
     definition['Properties']['read_only'] = True
     resource = docker_container.DockerContainer('Blog', definition,
                                                 self.stack)
     get_client_mock = self.patchobject(resource, 'get_client')
     get_client_mock.return_value = fakeclient.FakeDockerClient()
     get_client_mock.return_value.set_api_version('1.17')
     self.assertIsNone(resource.validate())
     scheduler.TaskRunner(resource.create)()
     self.assertEqual((resource.CREATE, resource.COMPLETE), resource.state)
     client = resource.get_client()
     self.assertEqual(['samalba/wordpress'], client.pulled_images)
     self.assertIs(True, client.container_start[0]['read_only'])
示例#6
0
 def test_create_with_name(self):
     t = template_format.parse(template)
     self.stack = utils.parse_stack(t)
     definition = self.stack.t.resource_definitions(self.stack)['Blog']
     definition['Properties']['name'] = 'super-blog'
     resource = docker_container.DockerContainer('Blog', definition,
                                                 self.stack)
     self.m.StubOutWithMock(resource, 'get_client')
     resource.get_client().MultipleTimes().AndReturn(
         fakeclient.FakeDockerClient())
     self.assertIsNone(resource.validate())
     self.m.ReplayAll()
     scheduler.TaskRunner(resource.create)()
     self.assertEqual((resource.CREATE, resource.COMPLETE), resource.state)
     client = resource.get_client()
     self.assertEqual(['samalba/wordpress'], client.pulled_images)
     self.assertEqual('super-blog', client.container_create[0]['name'])
示例#7
0
 def arg_for_low_api_version(self, arg, value, low_version):
     t = template_format.parse(template)
     self.stack = utils.parse_stack(t)
     definition = self.stack.t.resource_definitions(self.stack)['Blog']
     definition['Properties'][arg] = value
     my_resource = docker_container.DockerContainer('Blog', definition,
                                                    self.stack)
     get_client_mock = self.patchobject(my_resource, 'get_client')
     get_client_mock.return_value = fakeclient.FakeDockerClient()
     get_client_mock.return_value.set_api_version(low_version)
     msg = self.assertRaises(docker_container.InvalidArgForVersion,
                             my_resource.validate)
     min_version = docker_container.MIN_API_VERSION_MAP[arg]
     args = dict(arg=arg, min_version=min_version)
     expected = _('"%(arg)s" is not supported for API version '
                  '< "%(min_version)s"') % args
     self.assertEqual(expected, six.text_type(msg))
示例#8
0
 def test_start_with_caps(self):
     t = template_format.parse(template)
     self.stack = utils.parse_stack(t)
     definition = self.stack.t.resource_definitions(self.stack)['Blog']
     definition['Properties']['cap_add'] = ['NET_ADMIN']
     definition['Properties']['cap_drop'] = ['MKNOD']
     resource = docker_container.DockerContainer('Blog', definition,
                                                 self.stack)
     get_client_mock = self.patchobject(resource, 'get_client')
     get_client_mock.return_value = fakeclient.FakeDockerClient()
     self.assertIsNone(resource.validate())
     scheduler.TaskRunner(resource.create)()
     self.assertEqual((resource.CREATE, resource.COMPLETE), resource.state)
     client = resource.get_client()
     self.assertEqual(['samalba/wordpress'], client.pulled_images)
     self.assertEqual(['NET_ADMIN'], client.container_start[0]['cap_add'])
     self.assertEqual(['MKNOD'], client.container_start[0]['cap_drop'])
示例#9
0
 def test_start_with_restart_policy_always(self):
     t = template_format.parse(template)
     self.stack = utils.parse_stack(t)
     definition = self.stack.t.resource_definitions(self.stack)['Blog']
     definition['Properties']['restart_policy'] = {
         'Name': 'always',
         'MaximumRetryCount': 0
     }
     resource = docker_container.DockerContainer('Blog', definition,
                                                 self.stack)
     get_client_mock = self.patchobject(resource, 'get_client')
     get_client_mock.return_value = fakeclient.FakeDockerClient()
     self.assertIsNone(resource.validate())
     scheduler.TaskRunner(resource.create)()
     self.assertEqual((resource.CREATE, resource.COMPLETE), resource.state)
     client = resource.get_client()
     self.assertEqual(['samalba/wordpress'], client.pulled_images)
     self.assertEqual({
         'Name': 'always',
         'MaximumRetryCount': 0
     }, client.container_start[0]['restart_policy'])