# Path: lava_dispatcher/test/test_basic.py
# class Factory(object):
#     """
#     Not Model based, this is not a Django factory.
#     Factory objects are dispatcher based classes, independent
#     of any database objects.
#     """
# 
#     def __init__(self):
#         logging.basicConfig(stream=sys.stdout, level=logging.DEBUG)
#         logger = logging.getLogger('unittests')
#         logger.disabled = True
#         logger.propagate = False
#         logger = logging.getLogger('dispatcher')
#         logger.disabled = True
#         logger.propagate = False
# 
#     def create_fake_qemu_job(self):  # pylint: disable=no-self-use
#         device = NewDevice(os.path.join(os.path.dirname(__file__), '../devices/kvm01.yaml'))
#         sample_job_file = os.path.join(os.path.dirname(__file__), 'sample_jobs/basics.yaml')
#         parser = JobParser()
#         try:
#             with open(sample_job_file) as sample_job_data:
#                 job = parser.parse(sample_job_data, device, 4212, None, "")
#         except LAVAError:
#             # some deployments listed in basics.yaml are not implemented yet
#             return None
#         return job
# 
#     def create_kvm_job(self, filename):  # pylint: disable=no-self-use
#         device = NewDevice(os.path.join(os.path.dirname(__file__), '../devices/kvm01.yaml'))
#         kvm_yaml = os.path.join(os.path.dirname(__file__), filename)
#         parser = JobParser()
#         try:
#             with open(kvm_yaml) as sample_job_data:
#                 job = parser.parse(sample_job_data, device, 4212, None, "")
#             job.logger = DummyLogger()
#         except LAVAError as exc:
#             print(exc)
#             # some deployments listed in basics.yaml are not implemented yet
#             return None
#         return job
# 
# class StdoutTestCase(unittest.TestCase):  # pylint: disable=too-many-public-methods
# 
#     def setUp(self):
#         super(StdoutTestCase, self).setUp()
#         logger = logging.getLogger('dispatcher')
#         logger.disabled = True
#         logger.propagate = False
#         # set to True to update pipeline_references automatically.
#         self.update_ref = False
#         self.job = None
# 
#     def pipeline_reference(self, filename, job=None):
#         y_file = os.path.join(os.path.dirname(__file__), 'pipeline_refs', filename)
#         if self.update_ref:
#             if not job:
#                 job = self.job
#             sys.stderr.write('WARNING: modifying pipeline references!')
#             with open(y_file, 'w') as describe:
#                 yaml.dump(job.pipeline.describe(False), describe)
#         with open(y_file, 'r') as f_ref:
#             return yaml.load(f_ref)


from lava_dispatcher.test.test_basic import Factory, StdoutTestCase
# This file is part of LAVA Dispatcher.
#
# LAVA Dispatcher is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# LAVA Dispatcher 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 General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along
# with this program; if not, see <http://www.gnu.org/licenses>.



class TestCommand(StdoutTestCase):

    def setUp(self):
        super(TestCommand, self).setUp()
        factory = Factory()
        self.job = factory.create_kvm_job('sample_jobs/kvm-command.yaml')

    def test_pipeline(self):
        description_ref = self.pipeline_reference('kvm-command.yaml')
        self.assertEqual(description_ref, self.job.pipeline.describe(False))

        command = [action for action in self.job.pipeline.actions if action.name == 'user-command'][0]

# Path: lava_dispatcher/test/test_basic.py
# class Factory(object):
#     """
#     Not Model based, this is not a Django factory.
#     Factory objects are dispatcher based classes, independent
#     of any database objects.
#     """
# 
#     def __init__(self):
#         logging.basicConfig(stream=sys.stdout, level=logging.DEBUG)
#         logger = logging.getLogger('unittests')
#         logger.disabled = True
#         logger.propagate = False
#         logger = logging.getLogger('dispatcher')
#         logger.disabled = True
#         logger.propagate = False
# 
#     def create_fake_qemu_job(self):  # pylint: disable=no-self-use
#         device = NewDevice(os.path.join(os.path.dirname(__file__), '../devices/kvm01.yaml'))
#         sample_job_file = os.path.join(os.path.dirname(__file__), 'sample_jobs/basics.yaml')
#         parser = JobParser()
#         try:
#             with open(sample_job_file) as sample_job_data:
#                 job = parser.parse(sample_job_data, device, 4212, None, "")
#         except LAVAError:
#             # some deployments listed in basics.yaml are not implemented yet
#             return None
#         return job
# 
#     def create_kvm_job(self, filename):  # pylint: disable=no-self-use
#         device = NewDevice(os.path.join(os.path.dirname(__file__), '../devices/kvm01.yaml'))
#         kvm_yaml = os.path.join(os.path.dirname(__file__), filename)
#         parser = JobParser()
#         try:
#             with open(kvm_yaml) as sample_job_data:
#                 job = parser.parse(sample_job_data, device, 4212, None, "")
#             job.logger = DummyLogger()
#         except LAVAError as exc:
#             print(exc)
#             # some deployments listed in basics.yaml are not implemented yet
#             return None
#         return job
# 
# class StdoutTestCase(unittest.TestCase):  # pylint: disable=too-many-public-methods
# 
#     def setUp(self):
#         super(StdoutTestCase, self).setUp()
#         logger = logging.getLogger('dispatcher')
#         logger.disabled = True
#         logger.propagate = False
#         # set to True to update pipeline_references automatically.
#         self.update_ref = False
#         self.job = None
# 
#     def pipeline_reference(self, filename, job=None):
#         y_file = os.path.join(os.path.dirname(__file__), 'pipeline_refs', filename)
#         if self.update_ref:
#             if not job:
#                 job = self.job
#             sys.stderr.write('WARNING: modifying pipeline references!')
#             with open(y_file, 'w') as describe:
#                 yaml.dump(job.pipeline.describe(False), describe)
#         with open(y_file, 'r') as f_ref:
#             return yaml.load(f_ref)


# Path: lava_dispatcher/test/test_command.py
from lava_dispatcher.test.test_basic import Factory, StdoutTestCase

# This file is part of LAVA Dispatcher.
#
# LAVA Dispatcher is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# LAVA Dispatcher 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 General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along
# with this program; if not, see <http://www.gnu.org/licenses>.



class TestCommand(StdoutTestCase):

    def setUp(self):
        super(TestCommand, self).setUp()
        factory = Factory()
        self.job = factory.create_kvm_job('sample_jobs/kvm-command.yaml')

    def test_pipeline(self):
        description_ref = self.pipeline_reference('kvm-command.yaml')
        self.assertEqual(description_ref, self.job.pipeline.describe(False))

        command = [action for action in self.job.pipeline.actions if action.name == 'user-command'][0]

        self.assertEqual(command.parameters['name'], 'user_command_to_run')