Example #1
0
    def test_do_update_no_new_profile(self, mock_docker):
        obj = mock.Mock(physical_id='FAKE_ID')
        docker = dp.DockerProfile('container', self.spec)

        params = {}
        res = docker.do_update(obj, params)

        self.assertFalse(res)
Example #2
0
    def test_handle_stop_driver_failure(self, mock_docker):
        mock_docker.side_effect = exc.InternalError(message="Boom")
        obj = mock.Mock(physical_id='FAKE_ID')
        docker = dp.DockerProfile('container', self.spec)

        ex = self.assertRaises(exc.EResourceOperation, docker.handle_stop, obj)

        self.assertEqual("Failed in stop container 'FAKE_ID': "
                         "Boom.", str(ex))
    def test__get_host_node_found_by_node(self, mock_load):
        node = mock.Mock()
        mock_load.return_value = node
        ctx = mock.Mock()
        profile = dp.DockerProfile('container', self.spec)

        res = profile._get_host(ctx, 'host_node', None)

        self.assertEqual(node, res)
        mock_load.assert_called_once_with(ctx, node_id='host_node')
    def test_docker_client_wrong_host_type(self, mock_get):
        profile = mock.Mock(type_name='wrong_type')
        host = mock.Mock(rt={'profile': profile}, physical_id='server1')
        mock_get.return_value = host
        obj = mock.Mock()
        profile = dp.DockerProfile('container', self.spec)
        ex = self.assertRaises(exc.InternalError, profile.docker, obj)
        msg = _('Type of host node (wrong_type) is not supported')

        self.assertEqual(msg, ex.message)
Example #5
0
    def test_update_name(self, mock_docker):
        x_docker = mock.Mock()
        x_docker = mock_docker.return_value
        obj = mock.Mock(physical_id='FAKE_ID')

        docker = dp.DockerProfile('container', self.spec)
        res = docker._update_name(obj, 'NEW_NAME')

        self.assertIsNone(res)
        x_docker.rename.assert_called_once_with('FAKE_ID', 'NEW_NAME')
    def test_docker_client_get_host_ip_failed(self, mock_host, mock_ip):
        profile = mock.Mock(type_name='os.nova.server')
        host = mock.Mock(rt={'profile': profile}, physical_id='server1')
        mock_host.return_value = host
        mock_ip.return_value = None
        obj = mock.Mock()
        profile = dp.DockerProfile('container', self.spec)
        ex = self.assertRaises(exc.InternalError, profile.docker, obj)
        msg = _('Unable to determine the IP address of host node')

        self.assertEqual(msg, ex.message)
    def test_do_validate_with_cluster_and_node(self):
        spec = copy.deepcopy(self.spec)
        spec['properties']['host_cluster'] = 'fake_cluster'
        obj = mock.Mock()
        profile = docker_profile.DockerProfile('container', spec)

        ex = self.assertRaises(exc.InvalidSpec,
                               profile.do_validate, obj)

        self.assertEqual("Either 'host_cluster' or 'host_node' should be "
                         "specified, but not both.", six.text_type(ex))
 def test__get_random_node(self, mock_cluster):
     node1 = mock.Mock(status='ERROR')
     node2 = mock.Mock(status='ACTIVE')
     node3 = mock.Mock(status='ACTIVE')
     cluster = mock.Mock(rt={'nodes': [node1, node2, node3]})
     mock_cluster.return_value = cluster
     active_nodes = [node2, node3]
     profile = docker_profile.DockerProfile('container', self.spec)
     ctx = mock.Mock()
     node = profile._get_random_node(ctx, 'host_cluster')
     self.assertIn(node, active_nodes)
Example #9
0
    def test_handle_stop_with_timeout(self, mock_docker):
        x_docker = mock.Mock()
        x_docker = mock_docker.return_value
        obj = mock.Mock(physical_id='FAKE_ID')

        docker = dp.DockerProfile('container', self.spec)
        params = {'timeout': 200}
        res = docker.handle_stop(obj, **params)

        self.assertIsNone(res)
        mock_docker.assert_called_once_with(obj)
        x_docker.stop.assert_called_once_with('FAKE_ID', **params)
Example #10
0
    def test_check_container_same_name(self):
        obj = mock.Mock(physical_id='FAKE_ID')
        docker = dp.DockerProfile('container', self.spec)

        new_spec = {
            'type': 'container.dockerinc.docker',
            'version': '1.0',
            'properties': {
                'context': {
                    'region_name': 'RegionOne'
                },
                'name': 'docker_container',
                'image': 'hello-world',
                'command': '/bin/sleep 30',
                'port': 2375,
                'host_node': 'fake_node',
            }
        }
        new_profile = dp.DockerProfile('u', new_spec)
        res, new_name = docker._check_container_name(obj, new_profile)

        self.assertFalse(res)
Example #11
0
    def test_update_name_docker_failure(self, mock_docker):
        x_docker = mock.Mock()
        x_docker = mock_docker.return_value
        x_docker.rename.side_effect = exc.InternalError(message='BOOM')
        obj = mock.Mock(physical_id='FAKE_ID')
        docker = dp.DockerProfile('container', self.spec)

        ex = self.assertRaises(exc.EResourceUpdate, docker._update_name, obj,
                               'NEW_NAME')

        self.assertEqual("Failed in updating container 'FAKE_ID': BOOM.",
                         str(ex))
        x_docker.rename.assert_called_once_with('FAKE_ID', 'NEW_NAME')
    def test_get_host_ip_heat_stack(self):
        oc = mock.Mock()
        stack = mock.Mock(
            outputs=[{'output_key': 'fixed_ip', 'output_value': '1.2.3.4'}]
        )
        oc.stack_get.return_value = stack
        profile = docker_profile.DockerProfile('container', self.spec)
        profile._orchestrationclient = oc
        obj = mock.Mock()

        host_ip = profile._get_host_ip(obj, 'fake_node', 'os.heat.stack')

        self.assertEqual('1.2.3.4', host_ip)
        oc.stack_get.assert_called_once_with('fake_node')