This repository has been archived by the owner on Aug 22, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
added test for maintenance-mode subcommand and removed old testes rel…
…ated to maintenance-mode
- Loading branch information
Jameer Pathan
committed
Jun 20, 2019
1 parent
d3a6a9b
commit ec7236b
Showing
5 changed files
with
202 additions
and
63 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
# -*- encoding: utf-8 -*- | ||
""" | ||
Usage: | ||
foreman-maintain maintenance-mode [OPTIONS] SUBCOMMAND [ARG] ... | ||
Parameters: | ||
SUBCOMMAND subcommand | ||
[ARG] ... subcommand arguments | ||
Subcommands: | ||
start Start maintenance-mode | ||
stop Stop maintenance-mode | ||
status Get maintenance-mode status | ||
is-enabled Get maintenance-mode status code | ||
Options: | ||
-h, --help print help | ||
""" | ||
from testfm.base import Base | ||
|
||
|
||
class MaintenanceMode(Base): | ||
"""Manipulates Foreman-maintain's maintenance-mode command""" | ||
command_base = 'maintenance-mode' | ||
|
||
@classmethod | ||
def start(cls, options=None): | ||
"""foreman-maintain maintenance-mode start [OPTIONS]""" | ||
cls.command_sub = 'start' | ||
|
||
if options is None: | ||
options = {} | ||
|
||
result = cls._construct_command(options) | ||
|
||
return result | ||
|
||
@classmethod | ||
def stop(cls, options=None): | ||
"""foreman-maintain maintenance-mode stop [OPTIONS]""" | ||
cls.command_sub = 'stop' | ||
|
||
if options is None: | ||
options = {} | ||
|
||
result = cls._construct_command(options) | ||
|
||
return result | ||
|
||
@classmethod | ||
def status(cls, options=None): | ||
"""foreman-maintain maintenance-mode status [OPTIONS]""" | ||
cls.command_sub = 'status' | ||
|
||
if options is None: | ||
options = {} | ||
|
||
result = cls._construct_command(options) | ||
|
||
return result | ||
|
||
@classmethod | ||
def is_enabled(cls, options=None): | ||
"""foreman-maintain maintenance-mode is-enabled [OPTIONS]""" | ||
cls.command_sub = 'is-enabled' | ||
|
||
if options is None: | ||
options = {} | ||
|
||
result = cls._construct_command(options) | ||
|
||
return result | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,115 @@ | ||
from testfm.maintenance_mode import MaintenanceMode | ||
from testfm.log import logger | ||
import yaml | ||
|
||
|
||
def test_positive_maintenance_mode(setup_sync_plan, ansible_module): | ||
""" | ||
:param setup_sync_plan: | ||
:param ansible_module: | ||
:return: | ||
""" | ||
sync_ids, sat_hostname = setup_sync_plan() | ||
maintenance_mode_off = ['Status of maintenance-mode: Off', 'Iptables chain: absent', | ||
'sync plans: enabled', 'cron jobs: running'] | ||
maintenance_mode_on = ['Status of maintenance-mode: On', 'Iptables chain: present', | ||
'sync plans: disabled', 'cron jobs: not running'] | ||
|
||
# Verify maintenance-mode status | ||
setup = ansible_module.command(MaintenanceMode.status()) | ||
for result in setup.values(): | ||
logger.info(result['stdout']) | ||
assert "FAIL" not in result['stdout'] | ||
assert "OK" in result['stdout'] | ||
assert result["rc"] == 0 | ||
for i in maintenance_mode_off: | ||
assert i in result['stdout'] | ||
# Verify maintenance-mode is-enabled | ||
setup = ansible_module.command(MaintenanceMode.is_enabled()) | ||
for result in setup.values(): | ||
logger.info(result['stdout']) | ||
assert "FAIL" not in result['stdout'] | ||
assert "OK" in result['stdout'] | ||
assert result["rc"] == 1 | ||
assert 'Maintenance mode is Off' in result['stdout'] | ||
|
||
# Verify maintenance-mode start | ||
contacted = ansible_module.command(MaintenanceMode.start()) | ||
for result in contacted.values(): | ||
logger.info(result['stdout']) | ||
assert "FAIL" not in result['stdout'] | ||
assert result["rc"] == 0 | ||
assert "Total {} sync plans are now disabled.".format(len(sync_ids)) in result['stdout'] | ||
ansible_module.fetch( | ||
src="/var/lib/foreman-maintain/data.yml", | ||
dest="./" | ||
) | ||
with open('./{0}/var/lib/foreman-maintain/data.yml'.format(sat_hostname)) as f: | ||
data_yml = yaml.safe_load(f) | ||
assert len(sync_ids) == len(data_yml[':default'][':sync_plans'][':disabled']) | ||
assert sorted(sync_ids) == sorted(data_yml[':default'][':sync_plans'][':disabled']) | ||
check_iptables = ansible_module.command("iptables -L") | ||
for rules in check_iptables.values(): | ||
logger.info(rules['stdout']) | ||
assert "FOREMAN_MAINTAIN" in rules['stdout'] # Assert FOREMAN_MAINTAIN is listed iptables | ||
# Assert crond.service is stopped | ||
contacted = ansible_module.service_facts() | ||
assert 'stopped' in contacted.values()[0]['ansible_facts']['services']['crond.service']['state'] | ||
# Verify maintenance-mode status | ||
contacted = ansible_module.command(MaintenanceMode.status()) | ||
for result in contacted.values(): | ||
logger.info(result['stdout']) | ||
assert "FAIL" not in result['stdout'] | ||
assert "OK" in result['stdout'] | ||
assert result["rc"] == 0 | ||
for i in maintenance_mode_on: | ||
assert i in result['stdout'] | ||
# Verify maintenance-mode is-enabled | ||
contacted = ansible_module.command(MaintenanceMode.is_enabled()) | ||
for result in contacted.values(): | ||
logger.info(result['stdout']) | ||
assert "FAIL" not in result['stdout'] | ||
assert "OK" in result['stdout'] | ||
assert result["rc"] == 0 | ||
assert 'Maintenance mode is On' in result['stdout'] | ||
|
||
# Verify maintenance-mode stop | ||
contacted = ansible_module.command(MaintenanceMode.stop()) | ||
for result in contacted.values(): | ||
logger.info(result['stdout']) | ||
assert result["rc"] == 0 | ||
assert "FAIL" not in result['stdout'] | ||
assert "Total {} sync plans are now enabled.".format(len(sync_ids)) in result['stdout'] | ||
ansible_module.fetch( | ||
src="/var/lib/foreman-maintain/data.yml", | ||
dest="./" | ||
) | ||
with open('./{0}/var/lib/foreman-maintain/data.yml'.format(sat_hostname)) as f: | ||
data_yml = yaml.safe_load(f) | ||
assert len(sync_ids) == len(data_yml[':default'][':sync_plans'][':enabled']) | ||
assert sorted(sync_ids) == sorted(data_yml[':default'][':sync_plans'][':enabled']) | ||
check_iptables = ansible_module.command("iptables -L") | ||
for rules in check_iptables.values(): | ||
logger.info(rules['stdout']) | ||
assert "FOREMAN_MAINTAIN" not in rules['stdout'] # Assert FOREMAN_MAINTAIN not listed in iptables | ||
# Assert crond.service is running | ||
contacted = ansible_module.service_facts() | ||
assert 'running' in contacted.values()[0]['ansible_facts']['services']['crond.service']['state'] | ||
# Verify maintenance-mode status | ||
contacted = ansible_module.command(MaintenanceMode.status()) | ||
for result in contacted.values(): | ||
logger.info(result['stdout']) | ||
assert "FAIL" not in result['stdout'] | ||
assert "OK" in result['stdout'] | ||
assert result["rc"] == 0 | ||
for i in maintenance_mode_off: | ||
assert i in result['stdout'] | ||
# Verify maintenance-mode is-enabled | ||
contacted = ansible_module.command(MaintenanceMode.is_enabled()) | ||
for result in contacted.values(): | ||
logger.info(result['stdout']) | ||
assert "FAIL" not in result['stdout'] | ||
assert "OK" in result['stdout'] | ||
assert result["rc"] == 1 | ||
assert 'Maintenance mode is Off' in result['stdout'] |