Skip to content

Commit

Permalink
Add test for rho scan command
Browse files Browse the repository at this point in the history
Perform a scan on the machine which is running Camayoc.

Closes #17
  • Loading branch information
elyezer committed Aug 30, 2017
1 parent ba2d7b4 commit 028e201
Showing 1 changed file with 61 additions and 0 deletions.
61 changes: 61 additions & 0 deletions camayoc/tests/rho/test_scan.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
# coding=utf-8
"""Tests for ``rho scan`` commands.
:caseautomation: automated
:casecomponent: scan
:caseimportance: high
:requirement: RHO
:testtype: functional
:upstream: yes
"""
import os
from io import BytesIO

import pexpect

from camayoc import utils
from camayoc.tests.rho.utils import auth_add, input_vault_password


def test_scan(isolated_filesystem):
"""Scan one machine.
:id: 5be9627b-ed2f-46f4-9439-193cc2cf6ec6
:description: Scan a machine.
:steps: Run ``rho scan --profile <profile> --reportfile <reportfile>``
:expectedresults: A scan is perfomed and the report file is generated.
"""
auth_name = utils.uuid4()
profile_name = utils.uuid4()
hosts = 'localhost'
reportfile = utils.uuid4()
auth_add({
'name': auth_name,
'username': os.environ['USER'],
'sshkeyfile': os.path.join(os.environ['HOME'], '.ssh', 'id_rsa'),
})

rho_profile_add = pexpect.spawn(
'rho profile add --name {} --auth {} --hosts {}'
.format(profile_name, auth_name, hosts)
)
input_vault_password(rho_profile_add)
assert rho_profile_add.expect(
'Profile "{}" was added'.format(profile_name)) == 0
assert rho_profile_add.expect(pexpect.EOF) == 0
rho_profile_add.close()
assert rho_profile_add.exitstatus == 0

rho_scan = pexpect.spawn(
'rho scan --profile {} --reportfile {}'
.format(profile_name, reportfile),
timeout=300,
)
input_vault_password(rho_scan)
rho_scan.logfile = BytesIO()
assert rho_scan.expect(pexpect.EOF) == 0
logfile = rho_scan.logfile.getvalue().decode('utf-8')
rho_scan.logfile.close()
rho_scan.close()
assert rho_scan.exitstatus == 0, logfile
assert os.path.isfile(reportfile)

0 comments on commit 028e201

Please sign in to comment.