예제 #1
0
    def test_plugins_to_xml_result(self):
        # Mock: http://${hostname}:8089/  load_about
        # Mock: http://${hostname}:8089/plugins  open(resource='plugins')

        cli = smoker_client.Client(['%s:8086' % self.hostname])

        plugins = cli.get_plugins(filters=list())
        expected = '\n'.join(client_mock_result.xml_result_all_plugins)
        result = smoker_cli.plugins_to_xml(plugins)
        assert result == expected

        plugins = cli.get_plugins(filters=list(), exclude_plugins=['Hostname'])
        expected = '\n'.join(client_mock_result.xml_result_uptime_uname)
        result = smoker_cli.plugins_to_xml(plugins)
        assert result == expected

        plugins = cli.get_plugins(filters=list(), exclude_plugins=['Uname'])
        expected = '\n'.join(client_mock_result.xml_result_uptime_hostname)
        result = smoker_cli.plugins_to_xml(plugins)
        assert result == expected

        plugins = cli.get_plugins(filters=list(), exclude_plugins=['Uptime'])
        expected = '\n'.join(client_mock_result.xml_result_hostname_uname)
        result = smoker_cli.plugins_to_xml(plugins)
        assert result == expected
예제 #2
0
 def test_open_with_invalid_uri_and_resource(self):
     # Mock: http://${hostname}:8089/  load_about
     cli = smoker_client.Client(['%s:8086' % self.hostname])
     expected_exc = 'Argument uri or resource have to be submitted'
     expected_response = client_mock_result.about_response
     assert cli.open(uri='/InvalidUri')[self.hostname] == expected_response
     cli.open(resource='InvalidResource') == expected_response
     with pytest.raises(Exception) as exc_info:
         cli.open()
     assert expected_exc in repr(exc_info.value)
예제 #3
0
    def test_force_run(self):
        # Mock: http://${hostname}:8089/  load_about
        # Mock: http://${hostname}:8089/processes  open(resource='processes')
        # Mock: http://${hostname}:8089/processes/#  open(uri='/processes/#')

        cli = smoker_client.Client(['%s:8086' % self.hostname])
        plugins = cli.get_plugins(filters=list(),
                                  exclude_plugins=['Hostname', 'Uname'])
        result = cli.force_run(plugins)[self.hostname]
        assert result['status'] == 'OK'
        result = result['plugins']
        assert 'Uptime' in result
        assert 'Uname' and 'Hostname' not in result
        assert 'forcedResult' in result['Uptime']
        assert result['Uptime']['forcedResult']['status'] == 'OK'
        assert result['Uptime']['links']['self'] == '/plugins/Uptime'
예제 #4
0
    def test_get_plugins(self):
        # Mock: http://${hostname}:8089/  load_about
        # Mock: http://${hostname}:8089/plugins  open(resource='plugins')

        # Need confirm the format of filters. Look likes It doesn't work
        # filters = { 'Category': 'system'}
        # filters = ('Category', 'system')
        # filters = ['Uname', 'Uptime']
        cli = smoker_client.Client(['%s:8086' % self.hostname])
        result = cli.get_plugins(filters=list())
        assert self.hostname in result
        assert cli.hosts[0].load_about() == client_mock_result.about_response
        for x in ['Uname', 'Hostname', 'Uptime']:
            assert x in result[self.hostname]['plugins']

        result = cli.get_plugins(filters=list(), exclude_plugins=['Uname'])
        assert 'Hostname' and 'Uptime' in result[self.hostname]['plugins']
        assert 'Uname' not in result[self.hostname]['plugins']
예제 #5
0
 def test_get_plugins_with_filter_is_none(self):
     cli = smoker_client.Client(['%s:8086' % self.hostname])
     with pytest.raises(TypeError) as exc_info:
         cli.get_plugins()
     assert "'NoneType' object is not iterable" in repr(exc_info.value)
예제 #6
0
 def test_create_client_instance(self):
     # Mock: http://${hostname}:8089/  load_about
     cli = smoker_client.Client(['%s:8086' % self.hostname])
     assert cli.hosts[0].load_about() == client_mock_result.about_response