예제 #1
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'])
예제 #2
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.patchobject(resource, 'get_client', return_value=docker.Client())
     self.assertIsNone(resource.validate())
     scheduler.TaskRunner(resource.create)()
     self.assertEqual((resource.CREATE, resource.COMPLETE), resource.state)
     return resource
예제 #3
0
 def test_start_with_mapping_devices_not_set_path_in_container(self):
     t = template_format.parse(template)
     self.stack = utils.parse_stack(t)
     definition = self.stack.t.resource_definitions(self.stack)['Blog']
     props = t['Resources']['Blog']['Properties'].copy()
     props['devices'] = [{'path_on_host': '/dev/sda', 'permissions': 'rwm'}]
     my_resource = docker_container.DockerContainer(
         'Blog', definition.freeze(properties=props), self.stack)
     get_client_mock = self.patchobject(my_resource, 'get_client')
     get_client_mock.return_value = docker.Client()
     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/sda:rwm'],
                      client.container_start[0]['devices'])
예제 #4
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']
     props = t['Resources']['Blog']['Properties'].copy()
     props['restart_policy'] = {'Name': 'always', 'MaximumRetryCount': 0}
     resource = docker_container.DockerContainer(
         'Blog', definition.freeze(properties=props), self.stack)
     get_client_mock = self.patchobject(resource, 'get_client')
     get_client_mock.return_value = docker.Client()
     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'])
예제 #5
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']
     props = t['Resources']['Blog']['Properties'].copy()
     props['port_bindings'] = {'80/tcp': [{'HostPort': '80'}]}
     props['links'] = {'db': 'mysql'}
     resource = docker_container.DockerContainer(
         'Blog', definition.freeze(properties=props), self.stack)
     self.patchobject(resource, 'get_client', return_value=docker.Client())
     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({'db': 'mysql'}, client.container_start[0]['links'])
     self.assertEqual({'80/tcp': [{
         'HostPort': '80'
     }]}, client.container_start[0]['port_bindings'])
예제 #6
0
    def test_create_failed(self, test_client):
        t = template_format.parse(template)
        self.stack = utils.parse_stack(t)
        definition = self.stack.t.resource_definitions(self.stack)['Blog']
        props = t['Resources']['Blog']['Properties'].copy()

        mock_client = mock.Mock()
        mock_client.inspect_container.return_value = {
            "State": {
                "ExitCode": -1
            }
        }
        mock_client.logs.return_value = "Container startup failed"
        test_client.return_value = mock_client
        docker_res = docker_container.DockerContainer(
            'Blog', definition.freeze(properties=props), self.stack)
        exc = self.assertRaises(exception.ResourceInError,
                                docker_res.check_create_complete, 'foo')
        self.assertIn("Container startup failed", six.text_type(exc))