Esempio n. 1
0
 def setUp(self):
     config.data_repo = config.DataRepo(
         tempfile.mkdtemp(prefix='0robottest'))
     tcol.add_repo("https://github.com/threefoldtech/0-robot",
                   directory='tests/fixtures/templates')
     scol.drop_all()
     storage.init(config)
Esempio n. 2
0
    def test_service_create_uid(self):
        # make sure we don't have any template loaded in the current process
        tcol._templates = {}
        with self.assertRaises(TemplateNotFoundError, msg='trying to create a service from non handled template should raise '):
            self.api.services.create("github.com/threefoldtech/0-robot/node/0.0.1", 'node1')

        # load template in current process
        with tempfile.TemporaryDirectory(prefix="robotlocal") as tmpdir:
            config.data_repo = config.DataRepo(tmpdir)
            tcol.add_repo('http://github.com/threefoldtech/0-robot', directory='tests/fixtures/templates')
            # now that we have some templates loaded, it should create a local service
            node2 = self.api.services.create("github.com/threefoldtech/0-robot/node/0.0.1", 'node2')
            self.assertTrue(isinstance(node2, TemplateBase))

            # the api should get all services from the local robot only
            self.assertEqual(len(self.api.services.names), 1)
            self.assertEqual(len(self.api.services.guids), 1)
            # make sure remote robot doesn't have service created on them
            for instance in self.api.robots.list():
                robot = self.api.robots.get(instance)
                self.assertEqual(len(robot.services.names), 0)

        robot = self.api.robots.get('robot1')
        node = robot.services.create("github.com/threefoldtech/0-robot/node/0.0.1", 'node3')
        self.assertEqual(type(node), ServiceProxy, "service create on remote robot should return ServiceProxy")
        self.assertEqual(len(robot.services.guids), 1)
        # ensure we can access the remote service from the robot object
        assert robot.services.names[node.name]
        assert robot.services.guids[node.guid]
Esempio n. 3
0
 def preTest(cls, path, template):
     config.data_repo = config.DataRepo(
         tempfile.mkdtemp(prefix='0-templates_'))
     template_collection._load_template(
         'https://github.com/zero-os/0-templates', path)
     template.template_uid = TemplateUID.parse(
         'github.com/zero-os/0-templates/%s/%s' %
         (template.template_name, template.version))
Esempio n. 4
0
 def setUp(self):
     config.data_repo = config.DataRepo(tempfile.mkdtemp(prefix='0robottest'))
     scol.drop_all()
     tmpl = self._load_template('node')
     s = tmpl(name='test')
     self.tl = TaskList(s)
     # ensure we have a clean start
     self.tl._done.drop()
Esempio n. 5
0
    def test_service_find_or_create(self):
        with self.subTest(name='local'):
            # load template in current process
            with tempfile.TemporaryDirectory(prefix="robotlocal") as tmpdir:
                config.data_repo = config.DataRepo(tmpdir)
                tcol.add_repo('http://github.com/threefoldtech/0-robot', directory='tests/fixtures/templates')

                self._test_find_or_create(self.api)

        with self.subTest(name='remote'):
            self._test_find_or_create(self.api.robots.get('robot1'))
Esempio n. 6
0
    def test_service_exists(self):
        # load template in current process
        with self.subTest(name='local'):
            with tempfile.TemporaryDirectory(prefix="robotlocal") as tmpdir:
                config.data_repo = config.DataRepo(tmpdir)
                tcol.add_repo('http://github.com/zero-os/0-robot', directory='tests/fixtures/templates')

                self._test_exists(self.api)

        with self.subTest(name='remote'):
            self._test_exists(self.api.robots['robot1'])
Esempio n. 7
0
    def set_data_repo(self, url):
        """
        Set the data repository used to serialize services state.

        @param path: can be a git URL or a absolute path or None
            if git url: clone the repository locally, and use it as configuration repo
            if absolute path: make sure the directory exist and use it as configuration repo
            if None: automatically create a configuration repository in `{j.dirs.DATADIR}/zrobot`

        It can be the same of one of the template repository used.
        """
        config.data_repo = config.DataRepo(url)
        self.data_repo_url = url
Esempio n. 8
0
    def test_service_create_validate_fail(self):
        # make sure we don't have any template loaded in the current process
        tcol._templates = {}
        with self.assertRaises(TemplateNotFoundError, msg='trying to create a service from non handled template should raise '):
            self.api.services.create("validate", 'service1')

        # load template in current process
        with tempfile.TemporaryDirectory(prefix="robotlocal") as tmpdir:
            config.data_repo = config.DataRepo(tmpdir)
            tcol.add_repo('http://github.com/threefoldtech/0-robot', directory='tests/fixtures/templates')

        # try to create a service with wrong data, it should raise
        robot = self.api.robots.get('robot1')
        with pytest.raises(ServiceCreateError):
            service = robot.services.create("validate", 'service1')

        # create the same service with valid data, it should succeed
        assert len(robot.services.find()) == 0
        service = robot.services.create("validate", 'service1', {'required': True})
        assert len(robot.services.find()) == 1
 def setUp(self):
     config.data_repo = config.DataRepo(
         tempfile.mkdtemp(prefix='0robottest'))
     storage.init(config)
     scol.drop_all()
Esempio n. 10
0
 def setUp(self):
     config.data_repo = config.DataRepo(
         tempfile.mkdtemp(prefix='0robottest'))