Example #1
0
    def test_create_clusters(self, mock_get_datastore_version, mock_id_from_href, mock_cluster_create):
        body = self.cluster
        tenant_id = Mock()
        context = Mock()

        req = Mock()
        req.environ = Mock()
        req.environ.__getitem__ = Mock(return_value=context)
        datastore_version = Mock()
        datastore_version.manager = "mongodb"
        datastore = Mock()
        mock_get_datastore_version.return_value = (datastore, datastore_version)
        instances = [
            {"volume_size": 1, "flavor_id": "1234"},
            {"volume_size": 1, "flavor_id": "1234"},
            {"volume_size": 1, "flavor_id": "1234"},
            {"volume_size": 1, "flavor_id": "1234"},
            {"volume_size": 1, "flavor_id": "1234"},
        ]
        mock_id_from_href.return_value = "1234"

        mock_cluster = Mock()
        mock_cluster.instances = []
        mock_cluster.datastore_version.manager = "mongodb"
        mock_cluster_create.return_value = mock_cluster

        self.controller.create(req, body, tenant_id)
        mock_cluster_create.assert_called_with(context, "products", datastore, datastore_version, instances)
    def test_controller_action_multi_action(self, mock_cluster_load):

        body = {"do_stuff": {}, "do_stuff2": {}}
        tenant_id = Mock()
        context = trove_testtools.TroveTestContext(self)
        cluster_id = Mock()

        req = Mock()
        req.environ = MagicMock()
        req.environ.get = Mock(return_value=context)

        cluster = Mock()
        cluster.instances_without_server = [Mock()]
        cluster.datastore_version.manager = "test_dsv"
        mock_cluster_load.return_value = cluster

        self.assertRaisesRegexp(
            exception.TroveError,
            "should have exactly one action specified",
            self.controller.action,
            req,
            body,
            tenant_id,
            cluster_id,
        )
Example #3
0
    def test_controller_with_empty_metadata(self):
        """
        Test the mock controller with metadata
        """
        tenant_id = "77889991010"
        instance_id = "27e25b73-88a1-4526-b2b9-919a28b8b33f"
        context = Mock()

        req = Mock()
        req.environ = MagicMock()
        req.environ.get = Mock(return_value=context)

        send = Mock()
        UpgradeMessageSender.create = Mock(return_value=send)

        # append the body w/ empty metadata
        self.body["upgrade"]["metadata"] = {}

        resp = self.controller.create(req, self.body, tenant_id, instance_id)

        instance_version = self.body["upgrade"]["instance_version"]
        location = self.body["upgrade"]["location"]
        metadata = self.body["upgrade"]["metadata"]

        UpgradeMessageSender.create.assert_called_once_with(context, instance_id, instance_version, location, metadata)
        self.assertEqual(202, resp.status)
Example #4
0
    def test_controller_with_metadata(self):
        """
        Test the mock controller with metadata
        """
        tenant_id = "77889991010"
        instance_id = "27e25b73-88a1-4526-b2b9-919a28b8b33f"
        context = Mock()

        req = Mock()
        req.environ = MagicMock()
        req.environ.get = Mock(return_value=context)

        # append the body w/ metadata
        self.body["upgrade"]["metadata"] = {
            "config_location": "swift://my.conf.location",
            "is_public": True,
            "is_encypted": True,
        }

        resp = self.controller.create(req, self.body, tenant_id, instance_id)

        instance_version = self.body["upgrade"]["instance_version"]
        location = self.body["upgrade"]["location"]
        metadata = self.body["upgrade"]["metadata"]

        UpgradeMessageSender.create.assert_called_once_with(context, instance_id, instance_version, location, metadata)
        self.assertEqual(202, resp.status)
    def test_serve_asset_ok(self):
        """This test case makes sure valid assets are retrieved correctly to the client."""

        component_name = "component1"
        asset_path = "images/image.png"

        self._mock_os_provider(component_name, asset_path)

        content = b"simple test"

        request = Mock()
        request.environ = {}

        response = self._assets_contr.serve_asset(
            request,
            component_name,
            asset_path,
            os_provider=self._os_provider,
            file_loader=Mock(return_value=content),
            file_opener=Mock(),
        )

        self.assertIsNotNone(response)
        self.assertEqual(200, response.status_code)
        self.assertEqual("image/png", response.content_type)
        self.assertEqual(content, response.app_iter)
    def test_create_clusters(self, mock_get_datastore_version, mock_id_from_href, mock_cluster_create):
        body = self.cluster
        tenant_id = Mock()
        context = trove_testtools.TroveTestContext(self)

        req = Mock()
        req.environ = Mock()
        req.environ.__getitem__ = Mock(return_value=context)
        datastore_version = Mock()
        datastore_version.manager = "vertica"
        datastore = Mock()
        mock_get_datastore_version.return_value = (datastore, datastore_version)
        instances = [
            {
                "volume_size": 1,
                "volume_type": None,
                "flavor_id": "1234",
                "availability_zone": "az",
                "modules": None,
                "region_name": None,
                "nics": [{"net-id": "e89aa5fd-6b0a-436d-a75c-1545d34d5331"}],
            }
        ] * 3
        mock_id_from_href.return_value = "1234"

        mock_cluster = Mock()
        mock_cluster.instances = []
        mock_cluster.instances_without_server = []
        mock_cluster.datastore_version.manager = "vertica"
        mock_cluster_create.return_value = mock_cluster

        self.controller.create(req, body, tenant_id)
        mock_cluster_create.assert_called_with(context, "products", datastore, datastore_version, instances, {}, None)
    def test_serve_asset_unknown_mimetype(self):
        """This test case ensures a default mimetype is detected if the given file has an unknown extension."""

        component_name = "component1"
        asset_path = "images/image.unknown"

        self._mock_os_provider(component_name, asset_path)

        content = b"simple test"

        request = Mock()
        request.environ = {}

        response = self._assets_contr.serve_asset(
            request,
            component_name,
            asset_path,
            os_provider=self._os_provider,
            file_loader=Mock(return_value=content),
            file_opener=Mock(),
        )

        self.assertIsNotNone(response)
        self.assertEqual(200, response.status_code)
        self.assertEqual("application/octet-stream", response.content_type)
        self.assertEqual(content, response.app_iter)
 def test_instance_root_index(self, mock_cluster_root_load):
     context = Mock()
     req = Mock()
     req.environ = Mock()
     req.environ.__getitem__ = Mock(return_value=context)
     tenant_id = Mock()
     instance_id = utils.generate_uuid()
     self.controller.instance_root_index(req, tenant_id, instance_id)
     mock_cluster_root_load.assert_called_with(context, instance_id)
 def test_root_index(self, root_load):
     context = Mock()
     req = Mock()
     req.environ = Mock()
     req.environ.__getitem__ = Mock(return_value=context)
     tenant_id = Mock()
     uuid = utils.generate_uuid()
     is_cluster = False
     self.controller.root_index(req, tenant_id, uuid, is_cluster)
     root_load.assert_called_with(context, uuid)
Example #10
0
    def setUp(self):
        from wheezy.web.handlers.base import BaseHandler
        from wheezy.web.handlers.method import handler_factory

        self.options = {}
        mock_request = Mock()
        mock_request.options = self.options
        mock_request.environ = {"route_args": {}}
        self.handler = handler_factory(BaseHandler, mock_request)
        assert isinstance(self.handler, BaseHandler)
 def test_instance_root_index_exception(self, mock_cluster_root_load):
     context = Mock()
     req = Mock()
     req.environ = Mock()
     req.environ.__getitem__ = Mock(return_value=context)
     tenant_id = Mock()
     instance_id = utils.generate_uuid()
     self.assertRaises(
         exception.UnprocessableEntity, self.controller.instance_root_index, req, tenant_id, instance_id
     )
     mock_cluster_root_load.assert_called_with(context, instance_id)
Example #12
0
    def test_following_response_is_none(self):
        """ The following middleware returns None as response.
        """
        from wheezy.web.middleware.errors import HTTPErrorMiddleware

        mock_request = Mock()
        mock_request.environ = {"route_args": {"route_name": "http404"}}
        mock_following = Mock(return_value=None)
        middleware = HTTPErrorMiddleware({404: "http404"}, None)
        response = middleware(mock_request, mock_following)
        assert 404 == response.status_code
Example #13
0
    def test_following_error_pass_through(self):
        """ The following middleware raises error that pass
            through error middleware.
        """
        from wheezy.web.middleware.errors import HTTPErrorMiddleware

        mock_request = Mock()
        mock_request.environ = {"route_args": {"route_name": "http500"}}
        for error in [KeyboardInterrupt, SystemExit, MemoryError]:
            mock_following = Mock(side_effect=error)
            middleware = HTTPErrorMiddleware({}, None)
            self.assertRaises(error, lambda: middleware(mock_request, mock_following))
Example #14
0
    def test_following_is_none(self):
        """ There is no matching handler for incoming request
            and following middleware is None.
        """
        from wheezy.web.middleware.routing import PathRoutingMiddleware

        mock_request = Mock()
        mock_request.environ = {"PATH_INFO": "/en/signin"}
        mock_path_router = Mock()
        mock_path_router.match.return_value = (None, {})
        middleware = PathRoutingMiddleware(mock_path_router)
        assert None == middleware(mock_request, None)
        assert "route_args" in mock_request.environ
 def test_show_cluster_instance(self, mock_cluster_load_instance, mock_cluster_load):
     tenant_id = Mock()
     cluster_id = Mock()
     instance_id = Mock()
     context = Mock()
     req = Mock()
     req.environ = Mock()
     req.environ.__getitem__ = Mock(return_value=context)
     cluster = Mock()
     mock_cluster_load.return_value = cluster
     cluster.id = cluster_id
     self.controller.show_instance(req, tenant_id, cluster_id, instance_id)
     mock_cluster_load_instance.assert_called_with(context, cluster.id, instance_id)
 def test_instance_root_create_no_body(self, mock_cluster_root_create):
     user = Mock()
     context = Mock()
     context.user = Mock()
     context.user.__getitem__ = Mock(return_value=user)
     req = Mock()
     req.environ = Mock()
     req.environ.__getitem__ = Mock(return_value=context)
     password = None
     body = None
     instance_id = utils.generate_uuid()
     cluster_instances = Mock()
     self.controller.instance_root_create(req, body, instance_id, cluster_instances)
     mock_cluster_root_create.assert_called_with(context, instance_id, context.user, password, cluster_instances)
Example #17
0
    def test_following_raises_error(self):
        """ The following middleware raises unhandled error.
        """
        from wheezy.web.middleware.errors import HTTPErrorMiddleware

        mock_request = Mock()
        mock_request.environ = {"route_args": {"route_name": "http500"}}
        mock_logger = Mock()
        mock_following = Mock(side_effect=ValueError)
        middleware = HTTPErrorMiddleware({500: "http500"}, mock_logger)
        response = middleware(mock_request, mock_following)

        assert 500 == response.status_code
        assert mock_logger.error.called
Example #18
0
    def test_handler_is_none(self):
        """ There is no matching handler for incoming request.
        """
        from wheezy.web.middleware.routing import PathRoutingMiddleware

        mock_request = Mock()
        mock_request.environ = {"PATH_INFO": "/en/signin"}
        mock_following = Mock(return_value="response")
        mock_path_router = Mock()
        mock_path_router.match.return_value = (None, {})
        middleware = PathRoutingMiddleware(mock_path_router)
        assert "response" == middleware(mock_request, mock_following)
        assert "route_args" in mock_request.environ
        mock_path_router.match.assert_called_once_with("en/signin")
    def test_create_clusters_disabled(self, mock_get_datastore_version, mock_cluster_create):
        body = self.cluster
        tenant_id = Mock()
        context = trove_testtools.TroveTestContext(self)

        req = Mock()
        req.environ = MagicMock()
        req.environ.get = Mock(return_value=context)

        datastore_version = Mock()
        datastore_version.manager = "mysql"
        mock_get_datastore_version.return_value = (Mock(), datastore_version)

        self.assertRaises(exception.ClusterDatastoreNotSupported, self.controller.create, req, body, tenant_id)
 def test_root_create(self, root_create):
     user = Mock()
     context = Mock()
     context.user = Mock()
     context.user.__getitem__ = Mock(return_value=user)
     req = Mock()
     req.environ = Mock()
     req.environ.__getitem__ = Mock(return_value=context)
     tenant_id = Mock()
     uuid = utils.generate_uuid()
     is_cluster = False
     password = Mock()
     body = {"password": password}
     self.controller.root_create(req, body, tenant_id, uuid, is_cluster)
     root_create.assert_called_with(context, uuid, context.user, password)
Example #21
0
    def test_show_cluster(self, mock_cluster_load):
        tenant_id = Mock()
        id = Mock()
        context = Mock()
        req = Mock()
        req.environ = Mock()
        req.environ.__getitem__ = Mock(return_value=context)

        mock_cluster = Mock()
        mock_cluster.instances = []
        mock_cluster.datastore_version.manager = "mongodb"
        mock_cluster_load.return_value = mock_cluster

        self.controller.show(req, tenant_id, id)
        mock_cluster_load.assert_called_with(context, id)
Example #22
0
 def setUp(self):
     mock_os = Mock(name="os")
     mock_os.getuid.return_value = 0
     mock_os.environ = {}
     sys.modules["os"] = mock_os
     mock_pw_entry = Mock(name="pw_entry")
     mock_pw_entry.pw_name = "vigiconf"
     mock_pw_entry.pw_uid = 142
     mock_pw_entry.pw_gid = 242
     mock_pw_entry.pw_dir = "/home/for/vigiconf"
     mock_pw_entry.pw_shell = "/shell/for/vigiconf"
     mock_pwd = Mock(name="pwd")
     mock_pwd.getpwuid.return_value = mock_pw_entry
     mock_pwd.getpwnam.return_value = mock_pw_entry
     sys.modules["pwd"] = mock_pwd
Example #23
0
    def test_following_raises_error_extra_info(self):
        """ Ensure extra provider is called.
        """
        from wheezy.web.middleware.errors import HTTPErrorMiddleware

        mock_request = Mock()
        mock_request.environ = {"route_args": {"route_name": "http500"}}
        mock_logger = Mock()
        mock_extra_provider = Mock()
        mock_following = Mock(side_effect=ValueError)
        middleware = HTTPErrorMiddleware({500: "http500"}, mock_logger, mock_extra_provider)
        response = middleware(mock_request, mock_following)

        assert 500 == response.status_code
        mock_extra_provider.assert_called_once_with(mock_request)
        assert mock_logger.error.called
    def test_controller_action_no_strategy(self, mock_cluster_load):

        body = {"do_stuff2": {}}
        tenant_id = Mock()
        context = Mock()
        id = Mock()

        req = Mock()
        req.environ = MagicMock()
        req.environ.get = Mock(return_value=context)

        cluster = Mock()
        cluster.datastore_version.manager = "vertica"
        mock_cluster_load.return_value = cluster

        self.assertRaises(exception.TroveError, self.controller.action, req, body, tenant_id, id)
    def test_show_cluster(self, mock_cluster_load):
        tenant_id = Mock()
        id = Mock()
        context = trove_testtools.TroveTestContext(self)
        req = Mock()
        req.environ = Mock()
        req.environ.__getitem__ = Mock(return_value=context)

        mock_cluster = Mock()
        mock_cluster.instances = []
        mock_cluster.instances_without_server = []
        mock_cluster.datastore_version.manager = "vertica"
        mock_cluster_load.return_value = mock_cluster

        self.controller.show(req, tenant_id, id)
        mock_cluster_load.assert_called_with(context, id)
    def test_favicon_not_found(self):
        """This test case makes sure an empty response is retrieved if the icon is not found."""

        component_name = "static"
        asset_path = "favicon.ico"

        self._mock_os_provider(component_name, asset_path, file_exists=False, static_local=False)

        request = Mock()
        request.environ = {}

        response = self._assets_contr.handle_favicon(request, os_provider=self._os_provider)

        self.assertIsNotNone(response)
        self.assertEqual(200, response.status_code)
        self.assertTrue(response.content_type in ["image/vnd.microsoft.icon", "image/x-icon"])
        self.assertEqual(0, len(response.app_iter))
Example #27
0
    def test_following_response_needs_redirect(self):
        """ The following middleware returns error status
            that needs redirection to error page.
        """
        from wheezy.web.middleware.errors import HTTPErrorMiddleware

        mock_request = Mock()
        mock_path_for = Mock(return_value="not_found")
        mock_request.options = {"path_for": mock_path_for}
        mock_request.root_path = "my_site/"
        mock_request.method = "GET"
        mock_request.ajax = False
        mock_request.environ = {"route_args": {"route_name": "welcome"}}
        mock_following = Mock(return_value=None)
        middleware = HTTPErrorMiddleware({404: "http404"}, None)
        response = middleware(mock_request, mock_following)
        assert 302 == response.status_code
    def test_create_clusters_disabled(self, mock_cluster_create, mock_get_datastore_version):

        cfg.CONF.set_override("cluster_support", False, group="vertica", enforce_type=True)

        body = self.cluster
        tenant_id = Mock()
        context = trove_testtools.TroveTestContext(self)

        req = Mock()
        req.environ = MagicMock()
        req.environ.get = Mock(return_value=context)

        datastore_version = Mock()
        datastore_version.manager = "vertica"
        mock_get_datastore_version.return_value = (Mock(), datastore_version)

        self.assertRaises(exception.TroveError, self.controller.create, req, body, tenant_id)
    def test_controller_action_found(self, mock_cluster_load, mock_cluster_api_strategy):

        body = {"grow": {}}
        tenant_id = Mock()
        context = trove_testtools.TroveTestContext(self)
        cluster_id = "test_uuid"

        req = Mock()
        req.environ = MagicMock()
        req.environ.get = Mock(return_value=context)

        cluster = Mock()
        cluster.instances_without_server = [Mock()]
        cluster.datastore_version.manager = "test_dsv"
        mock_cluster_load.return_value = cluster

        self.controller.action(req, body, tenant_id, cluster_id)
        self.assertEqual(1, cluster.action.call_count)
    def test_create_clusters_disabled(self, mock_cluster_create, mock_get_datastore_version):

        cfg.CONF.set_override("cluster_support", False, group="redis")

        body = self.cluster
        tenant_id = Mock()
        context = Mock()

        req = Mock()
        req.environ = MagicMock()
        req.environ.get = Mock(return_value=context)

        datastore_version = Mock()
        datastore_version.manager = "redis"
        mock_get_datastore_version.return_value = (Mock(), datastore_version)

        self.assertRaisesRegexp(
            exception.TroveError, "Clusters not supported for", self.controller.create, req, body, tenant_id
        )