Ejemplo n.º 1
0
    def test_create_host_with_invalid_cluster(self):
        """
        Verify create_host returns INVALID_PARAMETERS when the cluster does not exist.
        """
        bus = mock.MagicMock()
        bus.storage.get.side_effect = (
            # Host doesn't exist yet
            _bus.RemoteProcedureCallError('test'),
            # Request the cluster which does not exist
            _bus.RemoteProcedureCallError('test'))

        self.assertEquals(
            expected_error(ID, JSONRPC_ERRORS['INVALID_PARAMETERS']),
            hosts.create_host.handler(CLUSTER_HOST_REQUEST, bus))
 def test_delete_cluster_that_does_not_exist(self):
     """
     Verify delete_cluster returns properly when the cluster doesn't exist.
     """
     bus = mock.MagicMock()
     bus.request.side_effect = (_bus.RemoteProcedureCallError('test'))
     self.assertEquals(expected_error(ID, JSONRPC_ERRORS['NOT_FOUND']),
                       clusters.delete_cluster(SIMPLE_CLUSTER_REQUEST, bus))
Ejemplo n.º 3
0
    def test_delete_host_not_found_on_missing_key(self):
        """
        Verify delete_host returns 404 on a missing host.
        """
        bus = mock.MagicMock()
        bus.storage.delete.side_effect = _bus.RemoteProcedureCallError('test')

        self.assertEquals(expected_error(ID, JSONRPC_ERRORS['NOT_FOUND']),
                          hosts.delete_host.handler(SIMPLE_HOST_REQUEST, bus))
Ejemplo n.º 4
0
    def test_delete_network_not_found_on_missing_key(self):
        """
        Verify delete_network returns 404 on a missing network.
        """
        bus = mock.MagicMock()
        bus.request.side_effect = _bus.RemoteProcedureCallError('test')

        self.assertEquals(expected_error(ID, JSONRPC_ERRORS['NOT_FOUND']),
                          networks.delete_network(SIMPLE_NETWORK_REQUEST, bus))
Ejemplo n.º 5
0
    def test_get_host_that_doesnt_exist(self):
        """
        Verify get_host responds with a 404 error on missing hosts.
        """
        bus = mock.MagicMock()
        bus.storage.get_host.side_effect = _bus.RemoteProcedureCallError(
            'test')

        self.assertEquals(expected_error(ID, JSONRPC_ERRORS['NOT_FOUND']),
                          hosts.get_host.handler(SIMPLE_HOST_REQUEST, bus))
    def test_get_cluster_deploy_that_doesnt_exist(self):
        """
        Verify get_cluster_deploy responds with a 404 error on missing cluster.
        """
        bus = mock.MagicMock()
        bus.storage.get.side_effect = _bus.RemoteProcedureCallError('test')

        self.assertEquals(
            expected_error(ID, JSONRPC_ERRORS['NOT_FOUND']),
            operations.get_cluster_deploy.handler(SIMPLE_DEPLOY_REQUEST, bus))
 def test_get_missing_container_manager(self):
     """
     Verify get_container_manager responds with 404 when it does not exist.
     """
     bus = mock.MagicMock()
     bus.storage.get.side_effect = _bus.RemoteProcedureCallError('test')
     self.assertEquals(
         expected_error(ID, JSONRPC_ERRORS['NOT_FOUND']),
         container_managers.get_container_manager.handler(
             SIMPLE_CONTAINER_MANAGER_CONFIG_REQUEST, bus))
    def test_delete_container_manager_not_found_on_missing_key(self):
        """
        Verify delete_container_manager returns 404 on a missing ContainerManagerConfig.
        """
        bus = mock.MagicMock()
        bus.storage.delete.side_effect = _bus.RemoteProcedureCallError('test')

        self.assertEquals(
            expected_error(ID, JSONRPC_ERRORS['NOT_FOUND']),
            container_managers.delete_container_manager.handler(
                SIMPLE_CONTAINER_MANAGER_CONFIG_REQUEST, bus))
    def test_create_cluster_deploy_with_rpc_error(self):
        """
        Verify create_cluster_deploy responds with an error when an rpc error occurs.
        """
        bus = mock.MagicMock()
        bus.request.side_effect = _bus.RemoteProcedureCallError('test')

        self.assertEquals(
            expected_error(ID, JSONRPC_ERRORS['INTERNAL_ERROR']),
            operations.create_cluster_deploy.handler(SIMPLE_DEPLOY_REQUEST,
                                                     bus))
Ejemplo n.º 10
0
 def test_create_network(self):
     """
     Verify create_network can create a new network.
     """
     bus = mock.MagicMock()
     bus.request.side_effect = (
         # Network doesn't yet exist
         _bus.RemoteProcedureCallError('test'),
         # Creation response
         create_response(ID, NETWORK.to_dict()))
     self.assertEquals(create_response(ID, NETWORK.to_dict()),
                       networks.create_network(SIMPLE_NETWORK_REQUEST, bus))
Ejemplo n.º 11
0
    def test_create_host(self):
        """
        Verify create_host saves new hosts.
        """
        bus = mock.MagicMock()
        # Host doesn't exist yet
        bus.storage.get_host.side_effect = _bus.RemoteProcedureCallError(
            'test')
        # Result from save
        bus.storage.save.return_value = HOST

        self.assertEquals(create_jsonrpc_response(ID, HOST.to_dict_safe()),
                          hosts.create_host.handler(SIMPLE_HOST_REQUEST, bus))
    def test_create_host(self):
        """
        Verify create_host saves new hosts.
        """
        bus = mock.MagicMock()
        bus.request.side_effect = (
            # Host doesn't exist yet
            _bus.RemoteProcedureCallError('test'),
            # Result from save
            create_response(ID, HOST.to_dict())
        )

        self.assertEquals(
            create_response(ID, HOST.to_dict()),
            hosts.create_host(SIMPLE_HOST_REQUEST, bus))
Ejemplo n.º 13
0
    def test_create_host_without_an_address(self):
        """
        Verify create_host returns INVALID_PARAMETERS when no address is given.
        """
        bus = mock.MagicMock()
        # Host doesn't exist yet
        bus.storage.get.side_effect = _bus.RemoteProcedureCallError('test')
        # Result from save
        bus.storage.save.return_value = HOST

        addressless = copy.deepcopy(SIMPLE_HOST_REQUEST)
        addressless['params'] = {}

        self.assertEquals(
            expected_error(ID, JSONRPC_ERRORS['INVALID_PARAMETERS']),
            hosts.create_host.handler(addressless, bus))
    def test_create_cluster_operation_with_missing_cluster(self):
        """
        Verify create_cluster_operation 404's when the cluster doesn't exist.
        """
        for model_instance, request in [
            (CLUSTER_UPGRADE, SIMPLE_UPGRADE_REQUEST),
            (CLUSTER_RESTART, SIMPLE_RESTART_REQUEST)
        ]:
            bus = mock.MagicMock()
            bus.request.side_effect = _bus.RemoteProcedureCallError('test')

            self.assertEquals(
                expected_error(ID, JSONRPC_ERRORS['NOT_FOUND']),
                operations.create_cluster_operation(model_instance.__class__,
                                                    request, bus,
                                                    'phony_routing_key'))
    def test_get_cluster_operation_that_doesnt_exist(self):
        """
        Verify get_cluster_operation responds with a 404 error on missing cluster.
        """
        for model_instance, request in [
            (CLUSTER_UPGRADE, SIMPLE_UPGRADE_REQUEST),
            (CLUSTER_RESTART, SIMPLE_RESTART_REQUEST)
        ]:

            bus = mock.MagicMock()
            bus.storage.get.side_effect = _bus.RemoteProcedureCallError('test')

            self.assertEquals(
                expected_error(ID, JSONRPC_ERRORS['NOT_FOUND']),
                operations.get_cluster_operation(model_instance.__class__,
                                                 request, bus))
    def test_create_host_without_an_address(self):
        """
        Verify create_host returns INVALID_PARAMETERS when no address is given.
        """
        bus = mock.MagicMock()
        bus.request.side_effect = (
            # Host doesn't exist yet
            _bus.RemoteProcedureCallError('test'),
            # Result from save
            create_response(ID, HOST.to_json())
        )

        addressless = copy.deepcopy(SIMPLE_HOST_REQUEST)
        addressless['params'] = {}

        self.assertEquals(
            expected_error(ID, JSONRPC_ERRORS['INVALID_PARAMETERS']),
            hosts.create_host(addressless, bus))
    def test_create_cluster_operation_with_rpc_error(self):
        """
        Verify create_cluster_operation responds with an error when an rpc error occurs.
        """
        for model_instance, request in [
            (CLUSTER_UPGRADE, SIMPLE_UPGRADE_REQUEST),
            (CLUSTER_RESTART, SIMPLE_RESTART_REQUEST)
        ]:
            bus = mock.MagicMock()
            # The cluster exists call
            bus.storage.get_cluster.return_value = None
            # The attempt to save
            bus.request.side_effect = _bus.RemoteProcedureCallError('test')

            self.assertEquals(
                expected_error(ID, JSONRPC_ERRORS['INTERNAL_ERROR']),
                operations.create_cluster_operation(model_instance.__class__,
                                                    request, bus,
                                                    'phony_routing_key'))
Ejemplo n.º 18
0
    def test_create_host_with_cluster(self):
        """
        Verify create_host saves new hosts with it's cluster.
        """
        bus = mock.MagicMock()

        # Host doesn't exist yet
        bus.storage.get_host.side_effect = _bus.RemoteProcedureCallError(
            'test')
        # Request the cluster
        bus.storage.get_cluster.return_value = Cluster.new(name='mycluster')
        bus.storage.save.side_effect = (
            # Cluster save (ignored)
            None,
            # Result from save
            HOST)

        self.assertEquals(create_jsonrpc_response(ID, HOST.to_dict_safe()),
                          hosts.create_host.handler(CLUSTER_HOST_REQUEST, bus))
    def test_create_host_with_cluster(self):
        """
        Verify create_host saves new hosts with it's cluster.
        """
        bus = mock.MagicMock()

        bus.request.side_effect = (
            # Host doesn't exist yet
            _bus.RemoteProcedureCallError('test'),
            # Request the cluster
            create_response(ID, {'hostset': []}),
            # Save of the cluster
            create_response(ID, {'hostset': []}),
            # Result from save (ignored)
            create_response(ID, HOST.to_dict())
        )

        self.assertEquals(
            create_response(ID, HOST.to_dict()),
            hosts.create_host(CLUSTER_HOST_REQUEST, bus))