Ejemplo n.º 1
0
class ParameterTest(GeneralParameterTest):
    """Tests for the Parameter class."""
    def setUp(self):
        super(ParameterTest, self).setUp()
        self.parameter1 = Parameter("foo", value="baz")

    def test_prompt_0(self):
        # Tests that when we have a value in the parameters and the user press
        # Enter, we get the old value back.
        self.mocked_raw_input.return_value = "\n"
        obtained = self.parameter1.prompt()
        self.assertEqual(self.parameter1.value, obtained)

    def test_prompt_1(self, ):
        # Tests that with a value stored in the parameter, if and EOFError is
        # raised when getting user input, we get back the old value.
        self.mocked_raw_input.side_effect = EOFError()
        obtained = self.parameter1.prompt()
        self.assertEqual(self.parameter1.value, obtained)

    def test_to_list_0(self):
        value = "a_value"
        expected = [value]
        obtained = to_list(value)
        self.assertIsInstance(obtained, list)
        self.assertEquals(expected, obtained)

    def test_to_list_1(self):
        expected = ["a_value", "b_value"]
        obtained = to_list(expected)
        self.assertIsInstance(obtained, list)
        self.assertEquals(expected, obtained)
    def setUp(self):
        super(CommandTest, self).setUp()
        self.args.FILE = self.temp_file.name
        self.args.type = "boot-test"

        self.device_type = Parameter('device_type')
        self.prebuilt_image = Parameter('prebuilt_image',
                                        depends=self.device_type)
        self.config = Config()
        self.config.put_parameter(self.device_type, 'foo')
        self.config.put_parameter(self.prebuilt_image, 'bar')
    def test_update_data(self):
        image = "/path/to/panda.img"
        param1 = Parameter("device_type")
        param2 = Parameter("image", depends=param1)
        self.config.put_parameter(param1, "panda")
        self.config.put_parameter(param2, image)

        job = Job(BOOT_TEST, self.temp_file.name)
        job.update(self.config)

        self.assertEqual(job.data['device_type'], "panda")
        self.assertEqual(job.data['actions'][0]["parameters"]["image"], image)
 def test_non_interactive_config_0(self):
     # Try to get a value that does not exists, users just press enter when
     # asked for a value. Value will be empty.
     self.config.force_interactive = False
     sys.stdin = StringIO("\n")
     value = self.config.get(Parameter("foo"))
     self.assertEqual("", value)
 def test_interactive_config_1(self):
     # Force to be interactive, but when asked for the new value press
     # Enter. The old value should be returned.
     self.config.force_interactive = True
     sys.stdin = StringIO("\n")
     value = self.config.get(Parameter("foo"))
     self.assertEqual("value", value)
 def test_interactive_config_0(self):
     # We force to be interactive, meaning that even if a value is found,
     # it will be asked anyway.
     self.config.force_interactive = True
     expected = "a_new_value"
     sys.stdin = StringIO(expected)
     value = self.config.get(Parameter("foo"))
     self.assertEqual(expected, value)
 def test_config_get_from_backend_public(self):
     # Need to to this, since we want a clean Config instance, with
     # a config_file with some content.
     with open(self.config.config_file, "w") as write_config:
         write_config.write("[DEFAULT]\nfoo=bar\n")
     param = Parameter("foo")
     obtained = self.config.get_from_backend(param)
     self.assertEquals("bar", obtained)
    def authenticated_server(self):
        """Returns a connection to a LAVA server.

        It will ask the user the necessary parameters to establish the
        connection.
        """
        print >> sys.stdout, "\nServer connection parameters:"

        server_name_parameter = Parameter("server")
        rpc_endpoint_parameter = Parameter("rpc_endpoint",
                                           depends=server_name_parameter)

        self.config.get(server_name_parameter)
        endpoint = self.config.get(rpc_endpoint_parameter)

        rpc_url = verify_and_create_url(endpoint)
        server = AuthenticatingServerProxy(rpc_url,
                                           auth_backend=KeyringAuthBackend())
        return server
    def test_config_get_0(self):
        # Tests that with a non existing parameter, it returns None.
        param = Parameter("baz")
        self.config._get_from_cache = MagicMock(return_value=None)
        self.config._calculate_config_section = MagicMock(
            return_value="DEFAULT")

        expected = None
        obtained = self.config.get(param)
        self.assertEqual(expected, obtained)
Ejemplo n.º 10
0
    def put(self, key, value, section=DEFAULT_SECTION):
        """Adds a parameter to the config file.

        :param key: The key to add.
        :param value: The value to add.
        :param section: The name of the section as in the config file.
        """
        if (not self.config_backend.has_section(section)
                and section != DEFAULT_SECTION):
            self.config_backend.add_section(section)

        # This is done to serialize a list when ConfigParser is written to
        # file. Since there is no real support for list in ConfigParser, we
        # serialized it in a common way that can get easily deserialized.
        if isinstance(value, list):
            value = Parameter.serialize(value)

        self.config_backend.set(section, key, value)
        # Store in the cache too.
        self._put_in_cache(key, value, section)
 def test_config_get_from_cache_1(self):
     self.config._put_in_cache("key", "value", "DEFAULT")
     obtained = self.config._get_from_cache(Parameter("key"), "DEFAULT")
     self.assertEqual("value", obtained)
# GNU General Public License for more details.
#
# You should have received a copy of the GNU Lesser General Public License
# along with lava-tool.  If not, see <http://www.gnu.org/licenses/>.

"""
This is just a place where to store a template like dictionary that
will be used to serialize a Device object.
"""

from copy import copy

from lava.parameter import Parameter

# The hostname parameter is always in the DEFAULT config section.
HOSTNAME_PARAMETER = Parameter("hostname")
DEVICE_TYPE_PARAMETER = Parameter("device_type", depends=HOSTNAME_PARAMETER)
CONNECTION_COMMAND_PARMAETER = Parameter("connection_command",
                                         depends=DEVICE_TYPE_PARAMETER)

DEFAULT_TEMPLATE = {
    'hostname': HOSTNAME_PARAMETER,
    'device_type': DEVICE_TYPE_PARAMETER,
    'connection_command': CONNECTION_COMMAND_PARMAETER,
}

# Specialized copies of the parameters.
# We need this or we might end up asking the user twice the same parameter due
# to different object references when one Parameter depends on a "specialized"
# one, different from the defaults.
PANDA_DEVICE_TYPE = copy(DEVICE_TYPE_PARAMETER)
Ejemplo n.º 13
0
 def setUp(self):
     super(ParameterTest, self).setUp()
     self.parameter1 = Parameter("foo", value="baz")
 def test_non_interactive_config_1(self):
     # Parent class config returns value, but we are not interactive.
     self.config.force_interactive = False
     value = self.config.get(Parameter("foo"))
     self.assertEqual("value", value)
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU Lesser General Public License
# along with lava-tool.  If not, see <http://www.gnu.org/licenses/>.
"""Test definition templates."""

from lava.parameter import (
    Parameter, )

DEFAULT_TESTDEF_VERSION = "1.0"
DEFAULT_TESTDEF_FORMAT = "Lava-Test Test Definition 1.0"
DEFAULT_ENVIRONMET_VALUE = "lava_test_shell"

# All these parameters will not be stored on the local config file.
NAME_PARAMETER = Parameter("name")
NAME_PARAMETER.store = False

DESCRIPTION_PARAMETER = Parameter("description", depends=NAME_PARAMETER)
DESCRIPTION_PARAMETER.store = False

TESTDEF_STEPS_KEY = "steps"

TESTDEF_TEMPLATE = {
    "metadata": {
        "name": NAME_PARAMETER,
        "format": DEFAULT_TESTDEF_FORMAT,
        "version": DEFAULT_TESTDEF_VERSION,
        "description": DESCRIPTION_PARAMETER,
        "environment": [DEFAULT_ENVIRONMET_VALUE],
    },
from lava_tool.utils import (
    base64_encode,
    create_dir,
    create_tar,
    edit_file,
    retrieve_file,
    write_file,
)

# Default directory structure name.
TESTS_DIR = "tests"

# Internal parameter ids.
JOBFILE_ID = "jobfile"

JOBFILE_PARAMETER = Parameter(JOBFILE_ID)
JOBFILE_PARAMETER.store = False

INIT_TEMPLATE = {
    JOBFILE_ID: JOBFILE_PARAMETER,
}


class init(BaseCommand):
    """Set-ups the base directory structure."""
    @classmethod
    def register_arguments(cls, parser):
        super(init, cls).register_arguments(parser)
        parser.add_argument("DIR",
                            help=("The name of the directory to initialize. "
                                  "Defaults to current working directory."),
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU Lesser General Public License
# along with lava-tool.  If not, see <http://www.gnu.org/licenses/>.

from lava.parameter import (
    ListParameter,
    Parameter,
)

LAVA_TEST_SHELL_TAR_REPO_KEY = "tar-repo"
LAVA_TEST_SHELL_TESDEF_KEY = "testdef"

DEVICE_TYPE_PARAMETER = Parameter("device_type")
PREBUILT_IMAGE_PARAMETER = Parameter("image", depends=DEVICE_TYPE_PARAMETER)

TESTDEF_URLS_PARAMETER = ListParameter("testdef_urls")
TESTDEF_URLS_PARAMETER.store = False

BOOT_TEST = {
    "timeout":
    18000,
    "job_name":
    "Boot test",
    "device_type":
    DEVICE_TYPE_PARAMETER,
    "actions": [{
        "command": "deploy_linaro_image",
        "parameters": {
 def test_non_interactive_config_2(self):
     self.config.force_interactive = False
     expected = "bar"
     sys.stdin = StringIO(expected)
     value = self.config.get(Parameter("foo"))
     self.assertEqual(expected, value)
 def setUp(self):
     super(ConfigTestCase, self).setUp()
     self.param1 = Parameter("foo")
     self.param2 = Parameter("bar", depends=self.param1)