This repository has been archived by the owner on Feb 2, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
13 changed files
with
458 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
commissaire.oscmd.atomic module | ||
=============================== | ||
|
||
.. automodule:: commissaire.oscmd.atomic | ||
:members: | ||
:undoc-members: | ||
:show-inheritance: |
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,7 @@ | ||
commissaire.oscmd.fedora module | ||
=============================== | ||
|
||
.. automodule:: commissaire.oscmd.fedora | ||
:members: | ||
:undoc-members: | ||
:show-inheritance: |
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,7 @@ | ||
commissaire.oscmd.rhel module | ||
============================= | ||
|
||
.. automodule:: commissaire.oscmd.rhel | ||
:members: | ||
:undoc-members: | ||
:show-inheritance: |
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,17 @@ | ||
commissaire.oscmd package | ||
========================= | ||
|
||
.. automodule:: commissaire.oscmd | ||
:members: | ||
:undoc-members: | ||
:show-inheritance: | ||
|
||
Submodules | ||
---------- | ||
|
||
.. toctree:: | ||
|
||
commissaire.oscmd.atomic | ||
commissaire.oscmd.fedora | ||
commissaire.oscmd.rhel | ||
|
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,64 @@ | ||
# Copyright (C) 2016 Red Hat, Inc | ||
# | ||
# This program is free software: you can redistribute it and/or modify | ||
# it under the terms of the GNU Affero General Public License as published by | ||
# the Free Software Foundation, either version 3 of the License, or | ||
# (at your option) any later version. | ||
# | ||
# This program is distributed in the hope that it will be useful, | ||
# but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
# GNU Affero General Public License for more details. | ||
# | ||
# You should have received a copy of the GNU Affero General Public License | ||
# along with this program. If not, see <http:// | ||
""" | ||
Abstraction of commands that change across operating systems. | ||
""" | ||
|
||
|
||
class OSCmdBase: | ||
""" | ||
Operating system command abstraction. | ||
""" | ||
|
||
#: The type of Operating System | ||
os_type = None | ||
|
||
def reboot(self): | ||
""" | ||
Reboot command. Must be overriden. | ||
:return: The command to execute as a list | ||
:rtype: list | ||
""" | ||
raise NotImplementedError('{0}.reboot() must be overriden.'.format( | ||
self.__class__.__name__)) | ||
|
||
def upgrade(self): | ||
""" | ||
Upgrade command. Must be overriden. | ||
:return: The command to execute as a list | ||
:rtype: list | ||
""" | ||
raise NotImplementedError('{0}.upgrade() must be overriden.'.format( | ||
self.__class__.__name__)) | ||
|
||
|
||
def get_oscmd(os_type): | ||
""" | ||
Returns the proper OSCmd class based on os_type. | ||
:param os_type: The type of OS: EX: fedora | ||
:type os_type: string | ||
:return: The proper OSCmd class. | ||
:rtype: commissaire.oscmd.OSCmdBase | ||
""" | ||
try: | ||
return getattr(__import__( | ||
'commissaire.oscmd.{0}'.format(os_type), | ||
fromlist=[True]), 'OSCmd') | ||
except ImportError: | ||
# TODO: Make this a specific exception | ||
raise Exception('No OSCmd class for {0}'.format(os_type)) |
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,46 @@ | ||
# Copyright (C) 2016 Red Hat, Inc | ||
# | ||
# This program is free software: you can redistribute it and/or modify | ||
# it under the terms of the GNU Affero General Public License as published by | ||
# the Free Software Foundation, either version 3 of the License, or | ||
# (at your option) any later version. | ||
# | ||
# This program is distributed in the hope that it will be useful, | ||
# but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
# GNU Affero General Public License for more details. | ||
# | ||
# You should have received a copy of the GNU Affero General Public License | ||
# along with this program. If not, see <http:// | ||
""" | ||
Atomic commands. | ||
""" | ||
|
||
from commissaire.oscmd import OSCmdBase | ||
|
||
|
||
class OSCmd(OSCmdBase): | ||
""" | ||
Commmands for Atomic. | ||
""" | ||
|
||
#: The type of Operating System | ||
os_type = 'atomic' | ||
|
||
def reboot(self): | ||
""" | ||
Atomic reboot command. | ||
:return: The command to execute as a list | ||
:rtype: list | ||
""" | ||
return ['systemctl', 'reboot'] | ||
|
||
def upgrade(self): | ||
""" | ||
Atomic upgrade command. | ||
:return: The command to execute as a list | ||
:rtype: list | ||
""" | ||
return ['rpm-ostree', 'upgrade'] |
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,46 @@ | ||
# Copyright (C) 2016 Red Hat, Inc | ||
# | ||
# This program is free software: you can redistribute it and/or modify | ||
# it under the terms of the GNU Affero General Public License as published by | ||
# the Free Software Foundation, either version 3 of the License, or | ||
# (at your option) any later version. | ||
# | ||
# This program is distributed in the hope that it will be useful, | ||
# but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
# GNU Affero General Public License for more details. | ||
# | ||
# You should have received a copy of the GNU Affero General Public License | ||
# along with this program. If not, see <http:// | ||
""" | ||
Fedora commands. | ||
""" | ||
|
||
from commissaire.oscmd import OSCmdBase | ||
|
||
|
||
class OSCmd(OSCmdBase): | ||
""" | ||
Commmands for Fedora. | ||
""" | ||
|
||
#: The type of Operating System | ||
os_type = 'fedora' | ||
|
||
def reboot(self): | ||
""" | ||
Fedora reboot command. | ||
:return: The command to execute as a list | ||
:rtype: list | ||
""" | ||
return ['systemctl', 'reboot'] | ||
|
||
def upgrade(self): | ||
""" | ||
Fedora upgrade command. | ||
:return: The command to execute as a list | ||
:rtype: list | ||
""" | ||
return ['dnf', 'update', '-y'] |
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,46 @@ | ||
# Copyright (C) 2016 Red Hat, Inc | ||
# | ||
# This program is free software: you can redistribute it and/or modify | ||
# it under the terms of the GNU Affero General Public License as published by | ||
# the Free Software Foundation, either version 3 of the License, or | ||
# (at your option) any later version. | ||
# | ||
# This program is distributed in the hope that it will be useful, | ||
# but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
# GNU Affero General Public License for more details. | ||
# | ||
# You should have received a copy of the GNU Affero General Public License | ||
# along with this program. If not, see <http:// | ||
""" | ||
RHEL commands. | ||
""" | ||
|
||
from commissaire.oscmd import OSCmdBase | ||
|
||
|
||
class OSCmd(OSCmdBase): | ||
""" | ||
Commmands for RHEL. | ||
""" | ||
|
||
#: The type of Operating System | ||
os_type = 'rhel' | ||
|
||
def reboot(self): | ||
""" | ||
RHEL reboot command. | ||
:return: The command to execute as a list | ||
:rtype: list | ||
""" | ||
return ['systemctl', 'reboot'] | ||
|
||
def upgrade(self): | ||
""" | ||
RHEL upgrade command. | ||
:return: The command to execute as a list | ||
:rtype: list | ||
""" | ||
return ['yum', 'update', '-y'] |
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,67 @@ | ||
# Copyright (C) 2016 Red Hat, Inc | ||
# | ||
# This program is free software: you can redistribute it and/or modify | ||
# it under the terms of the GNU Affero General Public License as published by | ||
# the Free Software Foundation, either version 3 of the License, or | ||
# (at your option) any later version. | ||
# | ||
# This program is distributed in the hope that it will be useful, | ||
# but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
# GNU Affero General Public License for more details. | ||
# | ||
# You should have received a copy of the GNU Affero General Public License | ||
# along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
""" | ||
Test cases for the commissaire.oscmd module. | ||
""" | ||
|
||
from . import TestCase | ||
from commissaire import oscmd | ||
|
||
|
||
class Test_OSCmdBase(TestCase): | ||
""" | ||
Tests for the OSCmdBase class. | ||
""" | ||
|
||
def before(self): | ||
""" | ||
Sets up a fresh instance of the class before each run. | ||
""" | ||
self.instance = oscmd.OSCmdBase() | ||
|
||
def test_oscmd_base_reboot_raises(self): | ||
""" | ||
Verify OSCmdBase's raises on reboot. | ||
""" | ||
self.assertRaises( | ||
NotImplementedError, | ||
self.instance.reboot) | ||
|
||
def test_oscmd_base_upgrade_raises(self): | ||
""" | ||
Verify OSCmdBase's raises on upgrade. | ||
""" | ||
self.assertRaises( | ||
NotImplementedError, | ||
self.instance.upgrade) | ||
|
||
|
||
class Test_get_oscmd(TestCase): | ||
|
||
def test_get_oscmd_with_valid_os_types(self): | ||
""" | ||
Verify get_oscmd returns proper modules. | ||
""" | ||
for os_type in ('atomic', 'fedora', 'rhel'): | ||
self.assertEquals( | ||
'commissaire.oscmd.{0}'.format(os_type), | ||
oscmd.get_oscmd(os_type).__module__) | ||
|
||
def test_get_oscmd_with_invalid_os_types(self): | ||
""" | ||
Verify get_oscmd errors when the os_type does not exist. | ||
""" | ||
|
||
self.assertRaises(Exception, oscmd.get_oscmd, 'not_a_real_os_type') |
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,50 @@ | ||
# Copyright (C) 2016 Red Hat, Inc | ||
# | ||
# This program is free software: you can redistribute it and/or modify | ||
# it under the terms of the GNU Affero General Public License as published by | ||
# the Free Software Foundation, either version 3 of the License, or | ||
# (at your option) any later version. | ||
# | ||
# This program is distributed in the hope that it will be useful, | ||
# but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
# GNU Affero General Public License for more details. | ||
# | ||
# You should have received a copy of the GNU Affero General Public License | ||
# along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
""" | ||
Test cases for the commissaire.oscmd.atomic module. | ||
""" | ||
|
||
from . import TestCase | ||
from commissaire.oscmd import atomic | ||
|
||
|
||
class Test_Atomic_OSCmd(TestCase): | ||
""" | ||
Tests for the OSCmd class for Atomic. | ||
""" | ||
|
||
def before(self): | ||
""" | ||
Sets up a fresh instance of the class before each run. | ||
""" | ||
self.instance = atomic.OSCmd() | ||
|
||
def test_atomic_oscmd_reboot(self): | ||
""" | ||
Verify Atomic's OSCmd returns proper data on reboot. | ||
""" | ||
cmd = self.instance.reboot() | ||
self.assertEquals( | ||
list, | ||
type(cmd)) | ||
|
||
def test_atomic_oscmd_base_upgrade(self): | ||
""" | ||
Verify Atomic's OSCmd returns proper data on upgrade. | ||
""" | ||
cmd = self.instance.upgrade() | ||
self.assertEquals( | ||
list, | ||
type(cmd)) |
Oops, something went wrong.