Esempio n. 1
0
    def test_create_container_bad_return_code(self):
        mock_conn = self.mox.CreateMockAnything()

        mock_conn.request('POST', '/v1.4/containers/create',
                          body=mox.IgnoreArg(),
                          headers={'Content-Type': 'application/json'})
        response = FakeResponse(400)
        mock_conn.getresponse().AndReturn(response)

        self.mox.ReplayAll()

        client = nova.virt.docker.client.DockerHTTPClient(mock_conn)
        container_id = client.create_container({})
        self.assertIsNone(container_id)

        self.mox.VerifyAll()
Esempio n. 2
0
    def test_create_container_no_id_in_response(self):
        mock_conn = self.mox.CreateMockAnything()

        mock_conn.request(
            "POST", "/v1.4/containers/create", body=mox.IgnoreArg(), headers={"Content-Type": "application/json"}
        )
        response = FakeResponse(201, data='{"ping": "pong"}', headers={"Content-Type": "application/json"})
        mock_conn.getresponse().AndReturn(response)

        self.mox.ReplayAll()

        client = nova.virt.docker.client.DockerHTTPClient(mock_conn)
        container_id = client.create_container({})
        self.assertEqual(None, container_id)

        self.mox.VerifyAll()
Esempio n. 3
0
    def test_create_container_no_id_in_response(self):
        mock_conn = self.mox.CreateMockAnything()

        mock_conn.request('POST', '/v1.4/containers/create',
                          body=mox.IgnoreArg(),
                          headers={'Content-Type': 'application/json'})
        response = FakeResponse(201, data='{"ping": "pong"}',
                                headers={'Content-Type': 'application/json'})
        mock_conn.getresponse().AndReturn(response)

        self.mox.ReplayAll()

        client = nova.virt.docker.client.DockerHTTPClient(mock_conn)
        container_id = client.create_container({})
        self.assertEqual(None, container_id)

        self.mox.VerifyAll()
Esempio n. 4
0
    def test_create_container_no_id_in_response(self):
        mock_conn = self.mox.CreateMockAnything()

        mock_conn.request('POST', '/v1.4/containers/create?name=FAKE_UUID',
                          body=mox.IgnoreArg(),
                          headers={'Content-Type': 'application/json'})
        response = FakeResponse(201, data='{"ping": "pong"}',
                                headers={'Content-Type': 'application/json'})
        mock_conn.getresponse().AndReturn(response)

        self.mox.ReplayAll()

        client = nova.virt.docker.client.DockerHTTPClient(mock_conn)
        container_id = client.create_container({},'FAKE_UUID')
        self.assertIsNone(container_id)

        self.mox.VerifyAll()
Esempio n. 5
0
    def test_create_container_with_args(self):
        mock_conn = self.mox.CreateMockAnything()
        expected_uuid = uuid.uuid4()
        expected_body = jsonutils.dumps({
            'Hostname': 'marco',
            'User': '',
            'Memory': 512,
            'MemorySwap': 0,
            'AttachStdin': False,
            'AttachStdout': False,
            'AttachStderr': False,
            'PortSpecs': [],
            'Tty': True,
            'OpenStdin': True,
            'StdinOnce': False,
            'Env': None,
            'Cmd': [],
            'Dns': None,
            'Image': 'example',
            'Volumes': {},
            'VolumesFrom': '',
        })
        mock_conn.request(
            'POST',
            '/v1.7/containers/create?name={0}'.format(expected_uuid),
            body=expected_body,
            headers={'Content-Type': 'application/json'})
        response = FakeResponse(201,
                                data='{"id": "XXX"}',
                                headers={'Content-Type': 'application/json'})
        mock_conn.getresponse().AndReturn(response)

        self.mox.ReplayAll()

        client = nova.virt.docker.client.DockerHTTPClient(mock_conn)
        args = {
            'Hostname': 'marco',
            'Memory': 512,
            'Image': 'example',
        }

        container_id = client.create_container(args, expected_uuid)
        self.assertEqual('XXX', container_id)

        self.mox.VerifyAll()
Esempio n. 6
0
    def test_create_container_with_args(self):
        mock_conn = self.mox.CreateMockAnything()
        expected_uuid = uuid.uuid4()
        expected_body = jsonutils.dumps({
            'Hostname': 'marco',
            'User': '',
            'Memory': 512,
            'MemorySwap': 0,
            'AttachStdin': False,
            'AttachStdout': False,
            'AttachStderr': False,
            'PortSpecs': [],
            'Tty': True,
            'OpenStdin': True,
            'StdinOnce': False,
            'Env': None,
            'Cmd': [],
            'Dns': None,
            'Image': 'example',
            'Volumes': {},
            'VolumesFrom': '',
        })
        mock_conn.request('POST', '/v1.7/containers/create?name={0}'.format(
            expected_uuid),
            body=expected_body,
            headers={'Content-Type': 'application/json'})
        response = FakeResponse(201, data='{"id": "XXX"}',
                                headers={'Content-Type': 'application/json'})
        mock_conn.getresponse().AndReturn(response)

        self.mox.ReplayAll()

        client = nova.virt.docker.client.DockerHTTPClient(mock_conn)
        args = {
            'Hostname': 'marco',
            'Memory': 512,
            'Image': 'example',
        }

        container_id = client.create_container(args, expected_uuid)
        self.assertEqual('XXX', container_id)

        self.mox.VerifyAll()
Esempio n. 7
0
    def test_create_container_with_args(self):
        mock_conn = self.mox.CreateMockAnything()

        expected_body = jsonutils.dumps(
            {
                "Hostname": "marco",
                "User": "",
                "Memory": 512,
                "MemorySwap": 0,
                "AttachStdin": False,
                "AttachStdout": False,
                "AttachStderr": False,
                "PortSpecs": [],
                "Tty": True,
                "OpenStdin": True,
                "StdinOnce": False,
                "Env": None,
                "Cmd": [],
                "Dns": None,
                "Image": "example",
                "Volumes": {},
                "VolumesFrom": "",
            }
        )
        mock_conn.request(
            "POST", "/v1.4/containers/create", body=expected_body, headers={"Content-Type": "application/json"}
        )
        response = FakeResponse(201, data='{"id": "XXX"}', headers={"Content-Type": "application/json"})
        mock_conn.getresponse().AndReturn(response)

        self.mox.ReplayAll()

        client = nova.virt.docker.client.DockerHTTPClient(mock_conn)
        args = {"Hostname": "marco", "Memory": 512, "Image": "example"}
        container_id = client.create_container(args)
        self.assertEqual("XXX", container_id)

        self.mox.VerifyAll()