2016-04-10 04:00:00 +00:00
|
|
|
#!/usr/bin/python3
|
2014-04-07 12:38:09 +00:00
|
|
|
#
|
|
|
|
# Copyright (C) 2013 Red Hat, Inc.
|
|
|
|
#
|
|
|
|
# This program is free software; you can redistribute it and/or modify
|
|
|
|
# it under the terms of the GNU Lesser General Public License as published
|
|
|
|
# by the Free Software Foundation; either version 2.1 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 Lesser General Public License for more details.
|
|
|
|
#
|
|
|
|
# You should have received a copy of the GNU Lesser General Public License
|
|
|
|
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
2016-04-10 04:00:00 +00:00
|
|
|
|
2014-04-07 12:38:09 +00:00
|
|
|
from mock import Mock
|
|
|
|
import unittest
|
2015-03-23 11:36:12 +00:00
|
|
|
import os
|
2014-04-07 12:38:09 +00:00
|
|
|
|
|
|
|
class BaseTestCase(unittest.TestCase):
|
|
|
|
def setUp(self):
|
|
|
|
import sys
|
|
|
|
|
|
|
|
sys.modules["anaconda_log"] = Mock()
|
|
|
|
sys.modules["block"] = Mock()
|
|
|
|
|
|
|
|
from pyanaconda import kickstart
|
|
|
|
import pykickstart.version
|
|
|
|
|
|
|
|
self.handler = pykickstart.version.makeVersion(kickstart.superclass.version)
|
|
|
|
self._commandMap = kickstart.commandMap
|
|
|
|
self._dataMap = kickstart.dataMap
|
|
|
|
|
|
|
|
# Verify that each kickstart command in anaconda uses the correct version of
|
|
|
|
# that command as provided by pykickstart. That is, if there's an FC3 and an
|
|
|
|
# F10 version of a command, make sure anaconda >= F10 uses the F10 version.
|
|
|
|
class CommandVersionTestCase(BaseTestCase):
|
|
|
|
def commands_test(self):
|
2015-03-23 11:36:12 +00:00
|
|
|
"""Test that anaconda uses the right versions of kickstart commands"""
|
2015-05-30 11:20:59 +00:00
|
|
|
for (commandName, commandObj) in self._commandMap.items():
|
2014-04-07 12:38:09 +00:00
|
|
|
pykickstartClass = self.handler.commands[commandName].__class__
|
|
|
|
self.assertIsInstance(commandObj(), pykickstartClass)
|
|
|
|
|
|
|
|
# Do the same thing as CommandVersionTestCase, but for data objects.
|
|
|
|
class DataVersionTestCase(BaseTestCase):
|
|
|
|
def data_test(self):
|
2015-03-23 11:36:12 +00:00
|
|
|
"""Test that anaconda uses the right versions of kickstart data"""
|
2015-05-30 11:20:59 +00:00
|
|
|
for (dataName, dataObj) in self._dataMap.items():
|
2014-04-07 12:38:09 +00:00
|
|
|
# pykickstart does not expose data objects as a mapping the way
|
|
|
|
# it does command objects.
|
|
|
|
pykickstartClass = eval("self.handler.%s" % dataName)
|
|
|
|
self.assertIsInstance(dataObj(), pykickstartClass)
|
2015-03-23 11:36:12 +00:00
|
|
|
|
|
|
|
# Copy the commands tests but with the command map from dracut/parse-kickstart
|
|
|
|
class DracutCommandVersionTestCase(CommandVersionTestCase):
|
|
|
|
def setUp(self):
|
|
|
|
CommandVersionTestCase.setUp(self)
|
|
|
|
|
|
|
|
# top_srcdir should have been set by nosetests.sh. If it wasn't, the KeyError
|
|
|
|
# will fail the test.
|
|
|
|
parse_kickstart_path = os.path.join(os.environ['top_srcdir'], 'dracut', 'parse-kickstart')
|
|
|
|
|
|
|
|
import tempfile
|
|
|
|
with tempfile.NamedTemporaryFile() as parse_temp:
|
|
|
|
# Compile the file manually to a tempfile so that the import doesn't automatically
|
|
|
|
# crud up the source directory with parse-kickstartc
|
|
|
|
import py_compile
|
|
|
|
parse_temp = tempfile.NamedTemporaryFile()
|
|
|
|
py_compile.compile(parse_kickstart_path, parse_temp.name)
|
2016-04-10 04:00:00 +00:00
|
|
|
with open(parse_temp.name, "rb") as parse_temp_content:
|
|
|
|
# Use imp to pretend that hyphens are ok for module names
|
|
|
|
import imp
|
|
|
|
parse_module = imp.load_module('parse_kickstart', parse_temp_content,
|
|
|
|
parse_temp.name, ('', 'rb', imp.PY_COMPILED))
|
2015-03-23 11:36:12 +00:00
|
|
|
|
|
|
|
self._commandMap = parse_module.dracutCmds
|