Esempio n. 1
0
    def setUp(self, m_parser, m_timezone, m_pyslurm):

        self.parser = MockConfigParser()
        # Return our instance of MockConfigParser when RawConfigParser is
        # instanciated in neos.conf.ConfLoader
        m_parser.return_value = self.parser
        # pytz.timezone() is used to return a tzinfo given in args to
        # datetime.fromtimestamp(). This method accepts None value, so use this
        # instead of writing a fake tzinfo object.
        m_timezone.return_value = None

        # configuration content for MockConfigParser
        self.parser.conf = {
            'cluster': {
                'name': 'computer',
                'partition': 'cg',
                'wanprefix': '',
            },
            'scenarios': {
                'dir': './neos/scenarios',
                'default': 'xfce4',
            },
            'internals': {
                'basedir': '~/.neos',
                'inenv': '/usr/lib/neos/exec/neos_inenv',
                'mcmd': '/usr/bin/modulecmd',
                'shell': 'bash',
            },
        }
        self.conf = Conf()
        self.loader = ConfLoader('fakepath')
        self.loader.update_conf(self.conf)

        # set environment variables to simulate Slurm job step environment
        set_job_env(1, 0, 'nodes[1-2]', 'cg')
        self.job = Job()
        # neos.scenario.Scenario.__init__() needs to parse SSH_CONNECTION
        # environment variable, then set it here.
        os.environ['SSH_CONNECTION'] = '127.0.0.1 foo'

        self.app = AppInEnv(self.conf, self.job)
Esempio n. 2
0
    def setUp(self, m_parser, m_timezone, m_pyslurm):

        self.parser = MockConfigParser()
        # Return our instance of MockConfigParser when RawConfigParser is
        # instanciated in neos.conf.ConfLoader
        m_parser.return_value = self.parser
        # pytz.timezone() is used to return a tzinfo given in args to
        # datetime.fromtimestamp(). This method accepts None value, so use this
        # instead of writing a fake tzinfo object.
        m_timezone.return_value = None

        # configuration content for MockConfigParser
        self.parser.conf = {
            'cluster': {
                'name': 'computer',
                'partition': 'cg',
                'wanprefix': '',
            },
            'scenarios': {
                'dir': './neos/scenarios',
                'default': 'xfce4',
            },
            'internals': {
                'basedir': '~/.neos',
                'inenv': '/usr/lib/neos/exec/neos_inenv',
                'mcmd': '/usr/bin/modulecmd',
                'shell': 'bash',
            },
        }
        self.conf = Conf()
        self.loader = ConfLoader('fakepath')
        self.loader.update_conf(self.conf)

        # set environment variables to simulate Slurm job step environment
        set_job_env(1, 0, 'nodes[1-2]', 'cg')
        self.job = Job()
        # neos.scenario.Scenario.__init__() needs to parse SSH_CONNECTION
        # environment variable, then set it here.
        os.environ['SSH_CONNECTION'] = '127.0.0.1 foo'

        self.app = AppInEnv(self.conf, self.job)
Esempio n. 3
0
class TestsAppInEnv(NeosTestCase):
    @mock.patch("neos.job.pyslurm")
    @mock.patch("neos.job.timezone")
    @mock.patch("neos.conf.ConfigParser.RawConfigParser")
    def setUp(self, m_parser, m_timezone, m_pyslurm):

        self.parser = MockConfigParser()
        # Return our instance of MockConfigParser when RawConfigParser is
        # instanciated in neos.conf.ConfLoader
        m_parser.return_value = self.parser
        # pytz.timezone() is used to return a tzinfo given in args to
        # datetime.fromtimestamp(). This method accepts None value, so use this
        # instead of writing a fake tzinfo object.
        m_timezone.return_value = None

        # configuration content for MockConfigParser
        self.parser.conf = {
            'cluster': {
                'name': 'computer',
                'partition': 'cg',
                'wanprefix': '',
            },
            'scenarios': {
                'dir': './neos/scenarios',
                'default': 'xfce4',
            },
            'internals': {
                'basedir': '~/.neos',
                'inenv': '/usr/lib/neos/exec/neos_inenv',
                'mcmd': '/usr/bin/modulecmd',
                'shell': 'bash',
            },
        }
        self.conf = Conf()
        self.loader = ConfLoader('fakepath')
        self.loader.update_conf(self.conf)

        # set environment variables to simulate Slurm job step environment
        set_job_env(1, 0, 'nodes[1-2]', 'cg')
        self.job = Job()
        # neos.scenario.Scenario.__init__() needs to parse SSH_CONNECTION
        # environment variable, then set it here.
        os.environ['SSH_CONNECTION'] = '127.0.0.1 foo'

        self.app = AppInEnv(self.conf, self.job)

    def test_init(self):
        """AppInEnv.__init__() runs w/o problem
        """
        pass

    @mock.patch("neos.scenario.call")
    @mock.patch("neos.scenario.check_output")
    @mock.patch("neos.scenario.Popen")
    def test_run(self, m_popen, m_checkoutput, m_call):
        """AppInEnv.run() runs w/o problem
        """
        # subprocess.check_output() in neos.scenario must return a string
        # as expected by the scenarios
        m_checkoutput.return_value = "mockoutput"
        # This test is pretty similar to neos command without additional args.
        # It is actually more a blackbox than a pure unit test, in the sense it
        # runs the full app in sandboxed environment, without all external
        # deps (pyslurm, pytz, clustershell and so on). Its purpose is just to
        # make sure quite a large portion of the code runs without major issue,
        # since it covers ~67% of neos code base by itself (measured when it
        # was initially introduced).
        self.assertEquals(0, self.app.run())
Esempio n. 4
0
    def load_conf_file(self, conf_path):
        """Parse config file and update app conf accordingly"""

        loader = ConfLoader(conf_path)
        loader.update_conf(self.conf)
Esempio n. 5
0
class TestsAppInEnv(NeosTestCase):

    @mock.patch("neos.job.pyslurm")
    @mock.patch("neos.job.timezone")
    @mock.patch("neos.conf.ConfigParser.RawConfigParser")
    def setUp(self, m_parser, m_timezone, m_pyslurm):

        self.parser = MockConfigParser()
        # Return our instance of MockConfigParser when RawConfigParser is
        # instanciated in neos.conf.ConfLoader
        m_parser.return_value = self.parser
        # pytz.timezone() is used to return a tzinfo given in args to
        # datetime.fromtimestamp(). This method accepts None value, so use this
        # instead of writing a fake tzinfo object.
        m_timezone.return_value = None

        # configuration content for MockConfigParser
        self.parser.conf = {
            'cluster': {
                'name': 'computer',
                'partition': 'cg',
                'wanprefix': '',
            },
            'scenarios': {
                'dir': './neos/scenarios',
                'default': 'xfce4',
            },
            'internals': {
                'basedir': '~/.neos',
                'inenv': '/usr/lib/neos/exec/neos_inenv',
                'mcmd': '/usr/bin/modulecmd',
                'shell': 'bash',
            },
        }
        self.conf = Conf()
        self.loader = ConfLoader('fakepath')
        self.loader.update_conf(self.conf)

        # set environment variables to simulate Slurm job step environment
        set_job_env(1, 0, 'nodes[1-2]', 'cg')
        self.job = Job()
        # neos.scenario.Scenario.__init__() needs to parse SSH_CONNECTION
        # environment variable, then set it here.
        os.environ['SSH_CONNECTION'] = '127.0.0.1 foo'

        self.app = AppInEnv(self.conf, self.job)

    def test_init(self):
        """AppInEnv.__init__() runs w/o problem
        """
        pass

    @mock.patch("neos.scenario.call")
    @mock.patch("neos.scenario.check_output")
    @mock.patch("neos.scenario.Popen")
    def test_run(self, m_popen, m_checkoutput, m_call):
        """AppInEnv.run() runs w/o problem
        """
        # subprocess.check_output() in neos.scenario must return a string
        # as expected by the scenarios
        m_checkoutput.return_value = "mockoutput"
        # This test is pretty similar to neos command without additional args.
        # It is actually more a blackbox than a pure unit test, in the sense it
        # runs the full app in sandboxed environment, without all external
        # deps (pyslurm, pytz, clustershell and so on). Its purpose is just to
        # make sure quite a large portion of the code runs without major issue,
        # since it covers ~67% of neos code base by itself (measured when it
        # was initially introduced).
        self.assertEquals(0, self.app.run())