Beispiel #1
0
 def _do_command(self):
     """Persist the server configuration."""
     server_config = {'host': self.args.host,
                      'port': int(self.args.port),
                      'use_http': self.args.use_http,
                      'ssl_verify': self.args.ssl_verify}
     write_server_config(server_config)
    def test_run_command_no_config(self):
        """Test running command without config."""
        write_server_config({})

        with self.assertRaises(SystemExit):
            sys.argv = ['/bin/qpc', 'cred']
            CLI().main()
Beispiel #3
0
 def setUp(self):
     """Create test setup."""
     write_server_config(DEFAULT_CONFIG)
     # Temporarily disable stderr for these tests, CLI errors clutter up
     # nosetests command.
     self.orig_stderr = sys.stderr
     sys.stderr = HushUpStderr()
Beispiel #4
0
 def setUp(self):
     """Create test setup."""
     write_server_config(DEFAULT_CONFIG)
     # Temporarily disable stderr for these tests, CLI errors clutter up
     # nosetests command.
     self.orig_stderr = sys.stderr
     self.test_tar_filename = 'test_%d.tar.gz' % time.time()
     sys.stderr = HushUpStderr()
    def test_invalid_configuration(self):
        """Test reading bad JSON on cli start."""
        write_server_config({})

        sys.argv = ['/bin/qpc', 'server', 'config', '--host', '127.0.0.1']
        CLI().main()
        config = read_server_config()
        self.assertEqual(config['host'], '127.0.0.1')
        self.assertEqual(config['port'], 8000)
Beispiel #6
0
 def setUp(self):
     """Create test setup."""
     write_server_config(DEFAULT_CONFIG)
     # Temporarily disable stderr for these tests, CLI errors clutter up
     # nosetests command.
     self.orig_stderr = sys.stderr
     sys.stderr = HushUpStderr()
     self.login_url = get_server_location() + LOGIN_URI
     self.success_json = {'token': 'a_token'}
Beispiel #7
0
 def setUp(self):
     """Create test setup."""
     write_server_config(
         {
             "host": "127.0.0.1",
             "port": 8000,
             "use_http": True,
             "require_token": False,
         }
     )
 def setUp(self):
     """Create test setup."""
     write_server_config(DEFAULT_CONFIG)
     # Temporarily disable stderr for these tests, CLI errors clutter up
     # nosetests command.
     self.orig_stderr = sys.stderr
     sys.stderr = HushUpStderr()
     if os.path.isfile(TMP_KEY):
         os.remove(TMP_KEY)
     with open(TMP_KEY, 'w') as test_sshkey:
         test_sshkey.write('fake ssh keyfile.')
Beispiel #9
0
 def setUp(self):
     """Create test setup."""
     # Temporarily disable stderr for these tests, CLI errors clutter up
     # nosetests command.
     self.orig_stderr = sys.stderr
     sys.stderr = HushUpStderr()
     utils.write_server_config({
         'host': '127.0.0.1',
         'port': 8000,
         'use_http': True
     })
Beispiel #10
0
 def setUp(self):
     """Create test setup."""
     # All cli commands require qpc config and qpc login to be executed,
     # require_token must be False, so we don't have to pass login info
     write_server_config(
         {
             "host": "127.0.0.1",
             "port": 8000,
             "use_http": True,
             "require_token": False,
         }
     )
Beispiel #11
0
 def setUp(self):
     """Create test setup."""
     write_server_config(DEFAULT_CONFIG)
     # Temporarily disable stderr for these tests, CLI errors clutter up
     # nosetests command.
     self.orig_stderr = sys.stderr
     sys.stderr = HushUpStderr()
     for file in JSON_FILES_LIST:
         if os.path.isfile(file[0]):
             os.remove(file[0])
         with open(file[0], 'w') as test_file:
             test_file.write(file[1])
Beispiel #12
0
 def setUp(self):
     """Create test setup."""
     write_server_config(DEFAULT_CONFIG)
     # Temporarily disable stderr for these tests, CLI errors clutter up
     # nosetests command.
     self.orig_stderr = sys.stderr
     sys.stderr = HushUpStderr()
     if os.path.isfile(TMP_HOSTFILE):
         os.remove(TMP_HOSTFILE)
     with open(TMP_HOSTFILE, 'w') as test_hostfile:
         test_hostfile.write('1.2.3.4\n')
         test_hostfile.write('1.2.3.[1:10]\n')
Beispiel #13
0
 def _do_command(self):
     """Persist the server configuration."""
     server_config = {
         'host': self.args.host,
         'port': int(self.args.port),
         'use_http': self.args.use_http,
         'ssl_verify': self.args.ssl_verify
     }
     write_server_config(server_config)
     protocol = 'https'
     if self.args.use_http:
         protocol = 'http'
     print(
         _(messages.SERVER_CONFIG_SUCCESS) %
         (protocol, self.args.host, self.args.port))
Beispiel #14
0
    def setUp(self):
        """Create test setup."""
        write_server_config(DEFAULT_CONFIG)
        # Temporarily disable stderr for these tests, CLI errors clutter up
        self.orig_stderr = sys.stderr
        self.success_json = {
            'report_id': 1,
            'report_type': 'insights',
            'report_version': '1.0.0.1b025b8',
            'status': 'completed',
            'report_platform_id': '5f2cc1fd-ec66-4c67-be1b-171a595ce319',
            'hosts': {
                '2f2cc1fd-ec66-4c67-be1b-171a595ce319': {
                    'bios_uuid': 'value'
                }
            }
        }
        self.json_missing_hosts = {
            'report_id': 1,
            'report_type': 'insights',
            'report_version': '1.0.0.1b025b8',
            'status': 'completed',
            'report_platform_id': '5f2cc1fd-ec66-4c67-be1b-171a595ce319',
            'hosts': {}
        }

        sys.stderr = HushUpStderr()
        # pylint:disable=line-too-long
        self.success_effect = [
            (None,
             b'Running Connection Tests...\nConnection test config:\n=== Begin Certificate Chain Test ===\ndepth=1\nverify error:num=0\nverify return:1\ndepth=0\nverify error:num=0\nverify return:1\n=== End Certificate Chain Test: SUCCESS ===\n\n=== Begin Upload URL Connection Test ===\nHTTP Status Code: 200\nHTTP Status Text: OK\nHTTP Response Text: \nSuccessfully connected to: https://cert-api.access.redhat.com/r/insights/uploads/\n=== End Upload URL Connection Test: SUCCESS ===\n\n=== Begin API URL Connection Test ===\nHTTP Status Code: 200\nHTTP Status Text: OK\nHTTP Response Text: lub-dub\nSuccessfully connected to: https://cert-api.access.redhat.com/r/insights/\n=== End API URL Connection Test: SUCCESS ===\n\n\nConnectivity tests completed successfully\nSee /var/log/insights-client/insights-client.log for more details.\n'
             ), (b'Client: 3.0.3-2\nCore: 3.0.72-1\n', b''),
            (None,
             b'Uploading Insights data.\nSuccessfully uploaded report for.\n')
        ]  # noqa: E501

        self.tmp_json_file = '/tmp/insights_tmp_%s.json' % (
            time.strftime('%Y%m%d_%H%M%S'))
        write_file(self.tmp_json_file, json.dumps(self.success_json), False)

        self.tmp_not_json_file = '/tmp/insights_tmp_%s.txt' % (
            time.strftime('%Y%m%d_%H%M%S'))
        write_file(self.tmp_not_json_file, 'not really json', False)

        self.tmp_invalid_insights_json = '/tmp/insights_invalid_tmp_%s.json' % (
            time.strftime('%Y%m%d_%H%M%S'))
        write_file(self.tmp_invalid_insights_json,
                   json.dumps(self.json_missing_hosts), False)
def _setup_server_config_file():
    """
    Create server config with require_token set to False.

    Since all cli commands require qpc config and qpc login to be executed,
    require_token must be False, to avoid passing login info
    """
    return write_server_config({
        "host": "127.0.0.1",
        "port": 8000,
        "use_http": True,
        "require_token": False,
    })
 def setUp(self):
     """Create test setup."""
     write_server_config(DEFAULT_CONFIG)
     # Temporarily disable stderr for these tests, CLI errors clutter up
     # nosetests command.
     self.orig_stderr = sys.stderr
     self.test_json_filename = 'test_%d.json' % time.time()
     self.test_csv_filename = 'test_%d.csv' % time.time()
     sys.stderr = HushUpStderr()
     if os.path.isfile(TMP_DETAILSFILE1):
         os.remove(TMP_DETAILSFILE1)
     with open(TMP_DETAILSFILE1, 'w') as test_details1:
         test_details1.write('{"id": 1, '
                             '"sources": [{"source_name": "source1"}]}')
     if os.path.isfile(TMP_DETAILSFILE2):
         os.remove(TMP_DETAILSFILE2)
     with open(TMP_DETAILSFILE2, 'w') as test_details2:
         test_details2.write('{"id": 1, '
                             '"sources": [{"source_name": "source2"}]}')
     if os.path.isfile(TMP_NOTJSONFILE):
         os.remove(TMP_NOTJSONFILE)
     with open(TMP_NOTJSONFILE, 'w') as test_notjson:
         test_notjson.write('Not a json file.')
Beispiel #17
0
 def _do_command(self):
     """Persist the server configuration."""
     server_config = {'host': self.args.host, 'port': int(self.args.port)}
     write_server_config(server_config)
Beispiel #18
0
from io import StringIO

from qpc.request import CONNECTION_ERROR_MSG, SSL_ERROR_MSG
from qpc.source import SOURCE_URI
from qpc.source.show import SourceShowCommand
from qpc.tests_utilities import HushUpStderr, redirect_stdout
from qpc.utils import get_server_location, write_server_config

import requests

import requests_mock

PARSER = ArgumentParser()
SUBPARSER = PARSER.add_subparsers(dest='subcommand')

write_server_config({'host': '127.0.0.1', 'port': 8000, 'use_http': True})
BASE_URL = get_server_location()
print(BASE_URL)


class SourceShowCliTests(unittest.TestCase):
    """Class for testing the source show commands for qpc."""
    def setUp(self):
        """Create test setup."""
        # Temporarily disable stderr for these tests, CLI errors clutter up
        # nosetests command.
        self.orig_stderr = sys.stderr
        sys.stderr = HushUpStderr()

    def tearDown(self):
        """Remove test setup."""
Beispiel #19
0
import unittest
import sys
from io import StringIO
from argparse import ArgumentParser, Namespace
import requests
import requests_mock
from qpc.tests_utilities import HushUpStderr, redirect_stdout
from qpc.request import CONNECTION_ERROR_MSG, SSL_ERROR_MSG
from qpc.source import SOURCE_URI
from qpc.source.list import SourceListCommand
from qpc.utils import get_server_location, write_server_config

PARSER = ArgumentParser()
SUBPARSER = PARSER.add_subparsers(dest='subcommand')

write_server_config({'host': '127.0.0.1', 'port': 8000})
BASE_URL = get_server_location()


class SourceListCliTests(unittest.TestCase):
    """Class for testing the source list commands for qpc."""
    def setUp(self):
        """Create test setup."""
        # Temporarily disable stderr for these tests, CLI errors clutter up
        # nosetests command.
        self.orig_stderr = sys.stderr
        sys.stderr = HushUpStderr()

    def tearDown(self):
        """Remove test setup."""
        # Restore stderr
Beispiel #20
0
 def setUp(self):
     """Create test setup."""
     write_server_config(DEFAULT_CONFIG)
     self.orig_stderr = sys.stderr
     sys.stderr = HushUpStderr()
     self.url = get_server_location() + ASYNC_MERGE_URI