def test_determine_inst(ids, kys, expct_inst, expct_idx):
    """Test valid and invalid params with det_instance function in awss."""
    global counter
    counter = 0

    def local_aminames(ami):
        for i in ami:
            ami[i]['aminame'] = ami_lookup[ami[i]['ami']]
        return ami

    def local_input(item1):
        global counter
        keye = kys[counter]
        counter += 1
        return keye

    with mock.patch('awss.awsc.get_all_aminames', local_aminames, create=True):
        with mock.patch('awss.core.obtain_input', local_input, create=True):
            if expct_inst:
                debg.init(True, True)
                (tar_inst, tar_idx) = determine_inst(ids, "TEST", "ssh")
                assert tar_inst == expct_inst
                assert tar_idx == expct_idx
            else:
                with pytest.raises(SystemExit):
                    debg.init(True, True)
                    tar_inst = determine_inst(ids, "TEST", "ssh")
                    pass
Beispiel #2
0
def test_display_list(capsys):
    """Test list_instances function in awss."""
    debg.init(False, False)
    outputTitle = "Test Report"
    list_instances(ii_all, outputTitle)
    out, err = capsys.readouterr()
    assert err == ""
def test_calc_sshuser(username, aminame, inst_name):
    """Test calculation of ssh login user based on image name."""

    debg.init(False, False)

    name_returned = cmd_ssh_user(aminame, inst_name)

    assert name_returned == username
Beispiel #4
0
def test_process_results(inputdata, resultdata):
    """Test process of converting raw data to i_info."""

    debg.init(False, False)

    ret_info = process_results(inputdata)

    assert ret_info[0]['id'] == resultdata[0]['id']
    assert ret_info[0]['state'] == resultdata[0]['state']
    assert ret_info[0]['ami'] == resultdata[0]['ami']
    assert ret_info[0]['ssh_key'] == resultdata[0]['ssh_key']
    assert ret_info[0]['pub_dns_name'] == resultdata[0]['pub_dns_name']
    assert ret_info[0]['tag'] == resultdata[0]['tag']
def test_query_generation(genid, genname, genstate):
    """Test all valid variations of params with qry_create function in awss."""
    print("TEST - Query_Parser  -   id: %s, name: %s, state: %s" %
          (genid, genname, genstate))

    qryoptions = holdOptions(genid, genname, genstate)
    debg.init(True, False)
    (genQuery, genTitle) = qry_create(qryoptions)

    resultIndex = idlu[genid] + namelu[genname] + statelu[genstate]
    expectedTitle = expected_results[resultIndex]['title']
    expectedQuery = expected_results[resultIndex]['query']

    assert genTitle == expectedTitle
    assert genQuery == expectedQuery
Beispiel #6
0
def main():
    """Collect user args and call command funct.

    Collect command line args and setup environment then call
    function for command specified in args.

    """
    parser = parser_setup()
    options = parser.parse_args()

    debug = bool(options.debug > 0)
    debugall = bool(options.debug > 1)

    awsc.init()
    debg.init(debug, debugall)
    print(C_NORM)

    options.func(options)

    sys.exit()
"""Test module for det_instance function in awss."""

from __future__ import print_function
import pytest
import mock

from awss.core import determine_inst
import awss.debg as debg

# import ami numbers to names lookup table
from awsstestdata import ami_lookup

debg.init(False, False)


@pytest.mark.parametrize(("ids", "kys", "expct_inst", "expct_idx"),
                         [({
                             0: {
                                 'ami': 'ami-16efb076',
                                 'id': 'i-0c875fafa1e71327b',
                                 'pub_dns_name': '',
                                 'ssh_key': 'robert',
                                 'state': 'stopped',
                                 'tag': {
                                     'Name': 'Ubuntu',
                                     'Role': 'Test'
                                 }
                             },
                             1: {
                                 'ami': 'ami-3e21725e',
                                 'id': 'i-0c459a77e113c6c9c',