Ejemplo n.º 1
0
    def test_should_not_detect_if_port_dont_match(self, rcp):
        expected_port = 6666
        actual_port = 8070

        # assume having python implementation
        FakeProcesses.cmdLine = _PYTHON_CMD_API
        FakeProcesses.inetConnections = [FakeInetConnection(actual_port)]

        # make sure we return the port as we would read from the cfg
        rcp.getint.return_value = expected_port

        # override configuration to make sure we read correct port
        impl_helper = mon._MonAPIPythonHelper()
        impl_helper._paste_config = rcp
        impl_helper.load_configuration = mock.Mock()

        self._mon_api._init_impl_helper = mock.Mock(return_value=impl_helper)

        with mock.patch.object(LOG, 'error') as mock_log_error:
            self._detect()
            self.assertFalse(self._mon_api.available)
            mock_log_error.assert_called_with('monasca-api is not listening '
                                              'on port %d. Plugin for '
                                              'monasca-api will not '
                                              'be configured.' % expected_port)
Ejemplo n.º 2
0
    def test_should_not_detect_if_port_dont_match(self, rcp):
        expected_port = 6666
        actual_port = 8070

        # assume having python implementation
        FakeProcesses.cmdLine = [_PYTHON_CMD_API]
        FakeProcesses.inetConnections = [FakeInetConnection(actual_port)]

        # make sure we return the port as we would read from the cfg
        rcp.getint.return_value = expected_port

        # override configuration to make sure we read correct port
        impl_helper = mon._MonAPIPythonHelper()
        impl_helper._paste_config = rcp
        impl_helper.load_configuration = mock.Mock()

        self._mon_api._init_impl_helper = mock.Mock(return_value=impl_helper)

        with mock.patch.object(LOG, 'error') as mock_log_error:
            self._detect()
            self.assertFalse(self._mon_api.available)
            mock_log_error.assert_called_with('monasca-api is not listening '
                                              'on port %d. Plugin for '
                                              'monasca-api will not '
                                              'be configured.' % expected_port)
Ejemplo n.º 3
0
    def test_should_use_config_file_from_args_for_python(self):
        FakeProcesses.cmdLine = _PYTHON_CMD_API
        custom_conf_file = '/tmp/mon.ini'
        plugin_args = {'paste-file': custom_conf_file}

        helper = mon._MonAPIPythonHelper(args=plugin_args)
        helper._read_config_file = rcf = mock.Mock()
        helper.get_bound_port = mock.Mock(return_value=123)

        self._mon_api._init_impl_helper = iih = mock.Mock(return_value=helper)
        self._detect(args=plugin_args)

        iih.assert_called_once_with(mock.ANY, 'python')
        rcf.assert_called_once_with(custom_conf_file)
        self.assertTrue(iih.get_bound_port.called_once)
Ejemplo n.º 4
0
    def test_should_use_config_file_from_args_for_python(self):
        fake_processes = FakeProcesses(name=TestMonAPIDetectionPlugin.fake_processes_name,
                                       cmd_line=_PYTHON_CMD_API)
        custom_conf_file = '/tmp/mon.ini'
        plugin_args = {'paste-file': custom_conf_file}

        helper = mon._MonAPIPythonHelper(args=plugin_args)
        helper._read_config_file = rcf = mock.Mock()
        helper.get_bound_port = mock.Mock(return_value=123)

        self._mon_api._init_impl_helper = iih = mock.Mock(
                return_value=helper
        )
        self._detect(args=plugin_args, retval=[fake_processes])

        iih.assert_called_once_with(mock.ANY, 'python')
        rcf.assert_called_once_with(custom_conf_file)
        self.assertTrue(iih.get_bound_port.called_once)
Ejemplo n.º 5
0
    def test_should_detect_python_api_has_config(self, rcp):
        expected_port = 6666
        actual_port = 6666

        FakeProcesses.cmdLine = _PYTHON_CMD_API
        FakeProcesses.inetConnections = [FakeInetConnection(actual_port)]

        # make sure we return the port as we would read from the cfg
        rcp.getint.return_value = expected_port

        # override configuration to make sure we read correct port
        impl_helper = mon._MonAPIPythonHelper()
        impl_helper._paste_config = rcp
        impl_helper.load_configuration = mock.Mock()

        self._mon_api._init_impl_helper = mock.Mock(return_value=impl_helper)

        self._detect()
        self.assertTrue(self._mon_api.available)
Ejemplo n.º 6
0
    def test_should_detect_python_api_has_config(self, rcp):
        expected_port = 6666
        actual_port = 6666

        FakeProcesses.cmdLine = [_PYTHON_CMD_API]
        FakeProcesses.inetConnections = [FakeInetConnection(actual_port)]

        # make sure we return the port as we would read from the cfg
        rcp.getint.return_value = expected_port

        # override configuration to make sure we read correct port
        impl_helper = mon._MonAPIPythonHelper()
        impl_helper._paste_config = rcp
        impl_helper.load_configuration = mock.Mock()

        self._mon_api._init_impl_helper = mock.Mock(return_value=impl_helper)

        self._detect()
        self.assertTrue(self._mon_api.available)
Ejemplo n.º 7
0
    def test_should_use_config_file_from_cmdline_for_python(self):
        paste_flags = '--paste', '--paster'
        for pf in paste_flags:
            paste_file = '/tmp/monasca-api-paste.ini'
            cmdline = _mock_python_cmd_api(paste_flag=pf,
                                           paste_file=paste_file)

            FakeProcesses.cmdLine = cmdline

            helper = mon._MonAPIPythonHelper(cmdline=cmdline)
            helper._read_config_file = rcf = mock.Mock()
            helper.get_bound_port = mock.Mock(return_value=123)

            self._mon_api._init_impl_helper = iih = mock.Mock(
                return_value=helper)
            self._detect()

            iih.assert_called_once_with(cmdline, 'python')
            rcf.assert_called_once_with(paste_file)
            self.assertTrue(iih.get_bound_port.called_once)
Ejemplo n.º 8
0
    def test_should_detect_python_api_has_config(self, rcp):
        expected_port = 6666
        actual_port = 6666

        fake_processes = FakeProcesses(name=TestMonAPIDetectionPlugin.fake_processes_name,
                                       cmd_line=_PYTHON_CMD_API,
                                       inet_connections=[FakeInetConnection(actual_port)])

        # make sure we return the port as we would read from the cfg
        rcp.getint.return_value = expected_port

        # override configuration to make sure we read correct port
        impl_helper = mon._MonAPIPythonHelper()
        impl_helper._paste_config = rcp
        impl_helper.load_configuration = mock.Mock()

        self._mon_api._init_impl_helper = mock.Mock(return_value=impl_helper)

        self._detect(retval=[fake_processes])
        self.assertTrue(self._mon_api.available)
Ejemplo n.º 9
0
    def test_build_python_config(self, rcp):
        expected_port = 8070

        FakeProcesses.cmdLine = _PYTHON_CMD_API
        FakeProcesses.inetConnections = [FakeInetConnection(expected_port)]

        rcp.getint.return_value = expected_port

        impl_helper = mon._MonAPIPythonHelper()
        impl_helper._paste_config = rcp
        impl_helper.load_configuration = mock.Mock()

        self._mon_api._init_impl_helper = mock.Mock(return_value=impl_helper)

        self._detect()
        conf = self._build_config()

        for key in ('process', ):
            self.assertIn(key, conf)
            bit = conf[key]
            self.assertIsNotNone(bit)
            self.assertNotEqual({}, bit)
Ejemplo n.º 10
0
    def test_build_python_config(self, rcp):
        expected_port = 8070

        FakeProcesses.cmdLine = [_PYTHON_CMD_API]
        FakeProcesses.inetConnections = [FakeInetConnection(expected_port)]

        rcp.getint.return_value = expected_port

        impl_helper = mon._MonAPIPythonHelper()
        impl_helper._paste_config = rcp
        impl_helper.load_configuration = mock.Mock()

        self._mon_api._init_impl_helper = mock.Mock(return_value=impl_helper)

        self._detect()
        conf = self._build_config()

        for key in ('process', ):
            self.assertIn(key, conf)
            bit = conf[key]
            self.assertIsNotNone(bit)
            self.assertNotEqual({}, bit)
Ejemplo n.º 11
0
    def test_should_use_config_file_from_cmdline_for_python(self):
        paste_flags = '--paste', '--paster'
        for pf in paste_flags:
            paste_file = '/tmp/monasca-api-paste.ini'
            cmdline = _mock_python_cmd_api(paste_flag=pf,
                                           paste_file=paste_file)

            fake_processes = FakeProcesses(name=TestMonAPIDetectionPlugin.fake_processes_name,
                                           cmd_line=cmdline)

            helper = mon._MonAPIPythonHelper(cmdline=cmdline)
            helper._read_config_file = rcf = mock.Mock()
            helper.get_bound_port = mock.Mock(return_value=123)

            self._mon_api._init_impl_helper = iih = mock.Mock(
                    return_value=helper
            )
            self._detect(retval=[fake_processes])

            iih.assert_called_once_with(cmdline, 'python')
            rcf.assert_called_once_with(paste_file)
            self.assertTrue(iih.get_bound_port.called_once)
Ejemplo n.º 12
0
    def test_build_python_config(self, rcp):
        expected_port = 8070

        fake_processes = FakeProcesses(name=TestMonAPIDetectionPlugin.fake_processes_name,
                                       cmd_line=_PYTHON_CMD_API,
                                       inet_connections=[FakeInetConnection(expected_port)])

        rcp.getint.return_value = expected_port

        impl_helper = mon._MonAPIPythonHelper()
        impl_helper._paste_config = rcp
        impl_helper.load_configuration = mock.Mock()

        self._mon_api._init_impl_helper = mock.Mock(return_value=impl_helper)

        self._detect(retval=[fake_processes])
        conf = self._build_config()

        for key in ('process', ):
            self.assertIn(key, conf)
            bit = conf[key]
            self.assertIsNotNone(bit)
            self.assertNotEqual({}, bit)
Ejemplo n.º 13
0
    def test_build_python_config(self, rcp):
        expected_port = 8070

        fake_processes = FakeProcesses(name=TestMonAPIDetectionPlugin.fake_processes_name,
                                       cmd_line=_PYTHON_CMD_API,
                                       inet_connections=[FakeInetConnection(expected_port)])

        rcp.getint.return_value = expected_port

        impl_helper = mon._MonAPIPythonHelper()
        impl_helper._paste_config = rcp
        impl_helper.load_configuration = mock.Mock()

        self._mon_api._init_impl_helper = mock.Mock(return_value=impl_helper)

        self._detect(retval=[fake_processes])
        conf = self._build_config()

        for key in ('process', ):
            self.assertIn(key, conf)
            bit = conf[key]
            self.assertIsNotNone(bit)
            self.assertNotEqual({}, bit)