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))
 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')
 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)
 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
    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)
 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)
 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))
 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)
 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"])
 def test_instantiate_generate_group_with_incorrect_parameters(self):
     with self.assertRaises(TypeError):
         generator.GenerateGroup()