def setUp(self):
     self.path = tempfile.mkdtemp()
     self.storage = YamlRepository(self.path)
Beispiel #2
0
 def setUp(self):
     self.path = tempfile.mkdtemp()
     self.storage = YamlRepository(self.path)
class YamlRepositoryTests(unittest.TestCase):
    def setUp(self):
        self.path = tempfile.mkdtemp()
        self.storage = YamlRepository(self.path)

    def tearDown(self):
        shutil.rmtree(self.path, ignore_errors=True)
        del self.storage

    def test_get_all(self):
        clusters = [
            Cluster(name="test_%d" % i, cloud_provider=None, setup_provider=None, user_key_name="key")
            for i in range(10)
        ]
        cluster_names = [c.name for c in clusters]

        for cluster in clusters:
            self.storage.save_or_update(cluster)

        new_clusters = self.storage.get_all()
        for cluster in new_clusters:
            assert cluster.name in cluster_names

    def test_get(self):
        clusters = [FakeCluster("test_%d" % i) for i in range(10)]

        for cluster in clusters:
            self.storage.save_or_update(cluster)

        new_clusters = [self.storage.get(cluster.name) for cluster in clusters]
        for cluster in new_clusters:
            assert cluster in clusters

    def test_delete(self):
        pass

    def test_save_and_delete(self):
        cluster = Cluster(name="test1", cloud_provider=None, setup_provider=None, user_key_name="key")
        self.storage.save_or_update(cluster)

        clusterpath = os.path.join(self.path, "test1.yaml")
        assert os.path.exists(clusterpath)

        self.storage.delete(cluster)
        assert not os.path.exists(clusterpath)

    def test_saving_cluster_with_nodes(self):
        cluster = Cluster(
            name="test1", cloud_provider=None, setup_provider=None, user_key_name="key", repository=self.storage
        )
        cluster.add_node(
            kind="foo", image_id="123", image_user="******", flavor="m1.tiny", security_group="default", name="foo123"
        )
        self.storage.save_or_update(cluster)
        new = self.storage.get(cluster.name)
        assert "foo" in cluster.nodes
        assert len(cluster.nodes["foo"]) > 0
        assert isinstance(cluster.nodes["foo"][0], Node)
        assert cluster.nodes["foo"][0].name == "foo123"
Beispiel #4
0
class YamlRepositoryTests(unittest.TestCase):
    def setUp(self):
        self.path = tempfile.mkdtemp()
        self.storage = YamlRepository(self.path)

    def tearDown(self):
        shutil.rmtree(self.path, ignore_errors=True)
        del self.storage

    def test_get_all(self):
        clusters = [Cluster(name='test_%d' % i,
                            cloud_provider=None,
                            setup_provider=None,
                            user_key_name='key') for i in range(10)]
        cluster_names = [c.name for c in clusters]

        for cluster in clusters:
            self.storage.save_or_update(cluster)

        new_clusters = self.storage.get_all()
        cluster_names = [c.name for c in clusters]
        for cluster in new_clusters:
            assert cluster.name in cluster_names

    def test_get(self):
        clusters = [Cluster('test_%d' % i) for i in range(10)]

        for cluster in clusters:
            self.storage.save_or_update(cluster)

        new_clusters = [self.storage.get(cluster.name) for cluster in clusters]
        for cluster in new_clusters:
            assert cluster in clusters

    def test_delete(self):
        pass

    def test_save_and_delete(self):
        cluster = Cluster(name='test1',
                          cloud_provider=None,
                          setup_provider=None,
                          user_key_name='key')
        self.storage.save_or_update(cluster)

        clusterpath = os.path.join(self.path, 'test1.yaml')
        assert os.path.exists(clusterpath)

        self.storage.delete(cluster)
        assert not os.path.exists(clusterpath)

    def test_saving_cluster_with_nodes(self):
        cluster = Cluster(name='test1',
                          cloud_provider=None,
                          setup_provider=None,
                          user_key_name='key',
                          repository=self.storage)
        cluster.add_node(kind='foo', image_id='123',
                         image_user='******', flavor='m1.tiny',
                         security_group='default', name='foo123')
        self.storage.save_or_update(cluster)
        new = self.storage.get(cluster.name)
        assert 'foo' in cluster.nodes
        assert len(cluster.nodes['foo']) > 0
        assert isinstance(cluster.nodes['foo'][0], Node)
        assert cluster.nodes['foo'][0].name == 'foo123'