コード例 #1
0
    def test_991_dump(self):
        _id = "etcd-test-%s" % self.test_991_dump.__name__
        new = generator.GenerateGroup(api_uri=self.api_uri,
                                      _id=_id,
                                      name="etcd-test",
                                      profile="etcd-test.yaml",
                                      matchbox_path=self.test_matchbox_path)
        self.assertTrue(new.dump())
        self.assertTrue(
            os.path.isfile("%s/groups/%s.json" %
                           (self.test_matchbox_path, _id)))

        self.assertFalse(new.dump())
        self.assertTrue(
            os.path.isfile("%s/groups/%s.json" %
                           (self.test_matchbox_path, _id)))

        new = generator.GenerateGroup(api_uri=self.api_uri,
                                      _id=_id,
                                      name="etcd-test",
                                      profile="etcd-test.yaml",
                                      matchbox_path=self.test_matchbox_path,
                                      selector={"one": "selector"})
        self.assertTrue(new.dump())
        self.assertTrue(
            os.path.isfile("%s/groups/%s.json" %
                           (self.test_matchbox_path, _id)))
        os.remove("%s/groups/%s.json" % (self.test_matchbox_path, _id))
コード例 #2
0
 def test_instantiate_generate_group_with_non_existing_matchbox_path(self):
     with self.assertRaises(OSError):
         generator.GenerateGroup(api_uri='foobar',
                                 _id='foo',
                                 name='foo-bar',
                                 profile='foo-bar-baz',
                                 matchbox_path='/foo/bar')
コード例 #3
0
 def test_990_generate(self):
     expect = {
         'profile': 'etcd-proxy.yaml',
         'metadata': {
             'api_uri': "%s" % self.gen.api_uri,
             'selector': {
                 'mac': '08:00:27:37:28:2e'
             },
             'ssh_authorized_keys': []
         },
         'id': 'etcd-proxy',
         'name': 'etcd-proxy',
         'selector': {
             'mac': '08:00:27:37:28:2e'
         }
     }
     new = generator.GenerateGroup(api_uri=self.api_uri,
                                   _id="etcd-proxy",
                                   name="etcd-proxy",
                                   profile="etcd-proxy.yaml",
                                   selector={"mac": "08:00:27:37:28:2e"},
                                   matchbox_path=self.test_matchbox_path)
     result = new.generate()
     result["metadata"]["ssh_authorized_keys"] = []
     self.assertEqual(expect, result)
コード例 #4
0
 def setUpClass(cls):
     super().setUpClass()
     cls.gen = generator.GenerateGroup(api_uri=cls.api_uri,
                                       _id="etcd-proxy",
                                       name="etcd-proxy",
                                       profile="TestGenerateProfiles",
                                       matchbox_path=cls.test_matchbox_path)
     cls.gen.profiles_path = cls.test_resources_path
コード例 #5
0
    def test_instantiate_generate_group(self):
        sandbox = mkdtemp(dir='/tmp')
        os.mkdir(os.path.join(sandbox, 'groups'))

        generator.GenerateGroup(api_uri='foobar',
                                _id='foo',
                                name='foo-bar',
                                profile='foo-bar-baz',
                                matchbox_path=sandbox)
        rmtree(sandbox)
コード例 #6
0
 def setUpClass(cls):
     super().setUpClass()
     os.environ["MATCHBOX_URI"] = "http://127.0.0.1:8080"
     os.environ["API_URI"] = "http://127.0.0.1:5000"
     cls.gen = generator.GenerateGroup(
         api_uri=cls.api_uri,
         _id="etcd-proxy",
         name="etcd-proxy",
         profile="TestGenerateProfiles",
         selector={"mac": "08:00:27:37:28:2E"},
         matchbox_path=cls.test_matchbox_path)
コード例 #7
0
 def test_991_dump(self):
     _id = "etcd-test-%s" % self.test_991_dump.__name__
     new = generator.GenerateGroup(api_uri=self.api_uri,
                                   _id="%s" % _id,
                                   name="etcd-test",
                                   profile="etcd-test.yaml",
                                   matchbox_path=self.test_matchbox_path,
                                   selector={"mac": "08:00:27:37:28:2e"})
     new.dump()
     self.assertTrue(
         os.path.isfile("%s/groups/%s.json" %
                        (self.test_matchbox_path, _id)))
     os.remove("%s/groups/%s.json" % (self.test_matchbox_path, _id))
コード例 #8
0
 def setUpClass(cls):
     super().setUpClass()
     os.environ["MATCHBOX_URI"] = "http://127.0.0.1:8080"
     os.environ["API_URI"] = "http://127.0.0.1:5000"
     cls.gen = generator.GenerateGroup(
         api_uri=cls.api_uri,
         _id="etcd-proxy",
         name="etcd-proxy",
         profile="TestGenerateProfiles",
         selector={"mac": "08:00:27:37:28:2E"},
         metadata={
             "etcd_initial_cluster": "static0=http://192.168.1.1:2379",
             "api_seed": "http://192.168.1.2:5000"
         },
         matchbox_path=cls.test_matchbox_path)
コード例 #9
0
 def test_990_generate(self):
     expect = {
         'profile': 'etcd-proxy.yaml',
         'metadata': {
             'api_uri': '%s' % self.gen.api_uri,
             'ssh_authorized_keys': []
         },
         'id': 'etcd-proxy',
         'name': 'etcd-proxy'
     }
     new = generator.GenerateGroup(api_uri=self.api_uri,
                                   _id="etcd-proxy",
                                   name="etcd-proxy",
                                   profile="etcd-proxy.yaml",
                                   matchbox_path=self.test_matchbox_path)
     result = new.generate()
     self.assertEqual(expect["profile"], result["profile"])
     self.assertEqual(expect["id"], result["id"])
     self.assertEqual(expect["name"], result["name"])
     self.assertEqual(expect["metadata"]["api_uri"],
                      result["metadata"]["api_uri"])
コード例 #10
0
 def test_instantiate_generate_group_with_incorrect_parameters(self):
     with self.assertRaises(TypeError):
         generator.GenerateGroup()