Example #1
0
    def test_continues_on_failure(self, version_cache):
        count = [1, 2]

        fake_server = mock.MagicMock()
        fake_server.workers = 123

        def fake_service(api, **kw):
            while count:
                count.pop()
                raise exception.PasteAppNotFound(name=api, path='/')
            return fake_server

        self.flags(enabled_apis=['foo', 'bar', 'baz'])
        with mock.patch.object(api, 'service') as mock_service:
            mock_service.WSGIService.side_effect = fake_service
            api.main()
            mock_service.WSGIService.assert_has_calls([
                mock.call('foo', use_ssl=False),
                mock.call('bar', use_ssl=False),
                mock.call('baz', use_ssl=False),
            ])
            launcher = mock_service.process_launcher.return_value
            launcher.launch_service.assert_called_once_with(fake_server,
                                                            workers=123)
        self.assertFalse(version_cache.called)
Example #2
0
    def test_continues_on_failure(self, version_cache):
        count = [1, 2]

        fake_server = mock.MagicMock()
        fake_server.workers = 123

        def fake_service(api, **kw):
            while count:
                count.pop()
                raise exception.PasteAppNotFound(name=api, path='/')
            return fake_server

        self.flags(enabled_apis=['foo', 'bar', 'baz'])
        with mock.patch.object(api, 'service') as mock_service:
            mock_service.WSGIService.side_effect = fake_service
            api.main()
            mock_service.WSGIService.assert_has_calls([
                mock.call('foo', use_ssl=False),
                mock.call('bar', use_ssl=False),
                mock.call('baz', use_ssl=False),
            ])
            launcher = mock_service.process_launcher.return_value
            launcher.launch_service.assert_called_once_with(
                fake_server, workers=123)
        self.assertFalse(version_cache.called)
Example #3
0
    def test_with_ec2(self, launcher):
        """Ensure that we don't explode if enabled_apis is wrong.

        If the end user hasn't updated their config, an ec2 entry
        might accidentally kill them in starting up their server. This
        tests that our new safety filter will prevent that.

        The metadata api is excluded because it loads a bunch of the
        network stack, which requires other mocking.
        """
        self.flags(enabled_apis=['ec2', 'osapi_compute'])
        # required because of where the portbind happens, so that we
        # collide on ports.
        self.flags(osapi_compute_listen_port=0)
        api.main()
Example #4
0
    def test_with_ec2(self, launcher):
        """Ensure that we don't explode if enabled_apis is wrong.

        If the end user hasn't updated their config, an ec2 entry
        might accidentally kill them in starting up their server. This
        tests that our new safety filter will prevent that.

        The metadata api is excluded because it loads a bunch of the
        network stack, which requires other mocking.
        """
        self.flags(enabled_apis=['ec2', 'osapi_compute'])
        # required because of where the portbind happens, so that we
        # collide on ports.
        self.flags(osapi_compute_listen_port=0)
        api.main()
Example #5
0
    def run_service(self):
        sys.argv = [""]
        sys.argv.append("--config-file")
        sys.argv.append("/etc/nova/nova.conf")

        service = self.service_name
        if service == "compute":
            sys.argv[0] = "nova-compute"
            compute.main()
        elif service == "conductor":
            sys.argv[0] = "nova-conductor"
            conductor.main()
        elif service == "scheduler":
            sys.argv[0] = "nova-scheduler"
            scheduler.main()
        elif service == "api":
            sys.argv[0] = "nova-api"
            api.main()
        else:
            raise RuntimeError("Unsupported service %s" % service)