예제 #1
0
    def test_all(self):
        a_storage_pool = models.StoragePool(self.client, name="lxd")
        # first assert that the lxd storage resource requires 'storage'
        # api_extension
        with self.assertRaises(exceptions.LXDAPIExtensionNotAvailable):
            a_storage_pool.volumes.all()

        # now make sure that it's available without mocking it out.
        add_api_extension_helper(self, ["storage"])

        volumes = a_storage_pool.volumes.all()

        # assert that we decoded stuff reasonably well.
        self.assertEqual(len(volumes), 9)
        self.assertEqual(volumes[0].type, "instance")
        self.assertEqual(volumes[0].name, "c1")
        self.assertEqual(volumes[1].type, "instance")
        self.assertEqual(volumes[1].name, "c2")
        self.assertEqual(volumes[2].type, "container")
        self.assertEqual(volumes[2].name, "c3")
        self.assertEqual(volumes[3].type, "container")
        self.assertEqual(volumes[3].name, "c4")
        self.assertEqual(volumes[4].type, "virtual-machine")
        self.assertEqual(volumes[4].name, "vm1")
        self.assertEqual(volumes[5].type, "virtual-machine")
        self.assertEqual(volumes[5].name, "vm2")
        self.assertEqual(volumes[6].type, "image")
        self.assertEqual(volumes[6].name, "i1")
        self.assertEqual(volumes[7].type, "image")
        self.assertEqual(volumes[7].name, "i2")
        self.assertEqual(volumes[8].type, "custom")
        self.assertEqual(volumes[8].name, "cu1")
예제 #2
0
    def test_patch(self):
        """A storage pool can be PATCHed"""
        a_storage_pool = models.StoragePool(self.client, name="lxd")
        patch_object = {"some": "value"}

        with mock.patch.object(self.client, "assert_has_api_extension"):
            a_storage_pool.patch(patch_object)
예제 #3
0
    def test_patch(self):
        """A storage pool can be PATCHed"""
        a_storage_pool = models.StoragePool(self.client, name='lxd')
        patch_object = {'some': 'value'}

        with mock.patch.object(self.client, 'assert_has_api_extension'):
            a_storage_pool.patch(patch_object)
예제 #4
0
파일: test_storage.py 프로젝트: pstch/pylxd
    def test_all(self):
        a_storage_pool = models.StoragePool(self.client, name='lxd')
        # first assert that the lxd storage resource requires 'storage'
        # api_extension
        with self.assertRaises(exceptions.LXDAPIExtensionNotAvailable):
            a_storage_pool.volumes.all()

        # now make sure that it's available without mocking it out.
        add_api_extension_helper(self, ['storage'])

        volumes = a_storage_pool.volumes.all()

        # assert that we decoded stuff reasonably well.
        self.assertEqual(len(volumes), 9)
        self.assertEqual(volumes[0].type, 'instance')
        self.assertEqual(volumes[0].name, 'c1')
        self.assertEqual(volumes[1].type, 'instance')
        self.assertEqual(volumes[1].name, 'c2')
        self.assertEqual(volumes[2].type, 'container')
        self.assertEqual(volumes[2].name, 'c3')
        self.assertEqual(volumes[3].type, 'container')
        self.assertEqual(volumes[3].name, 'c4')
        self.assertEqual(volumes[4].type, 'virtual-machine')
        self.assertEqual(volumes[4].name, 'vm1')
        self.assertEqual(volumes[5].type, 'virtual-machine')
        self.assertEqual(volumes[5].name, 'vm2')
        self.assertEqual(volumes[6].type, 'image')
        self.assertEqual(volumes[6].name, 'i1')
        self.assertEqual(volumes[7].type, 'image')
        self.assertEqual(volumes[7].name, 'i2')
        self.assertEqual(volumes[8].type, 'custom')
        self.assertEqual(volumes[8].name, 'cu1')
예제 #5
0
    def test_save(self):
        """A storage pool can be saved"""
        a_storage_pool = models.StoragePool(self.client, name='lxd')
        a_storage_pool.config = {'some': 'value'}

        with mock.patch.object(self.client, 'assert_has_api_extension'):
            a_storage_pool.save()
예제 #6
0
    def test_save(self):
        """A storage pool can be saved"""
        a_storage_pool = models.StoragePool(self.client, name="lxd")
        a_storage_pool.config = {"some": "value"}

        with mock.patch.object(self.client, "assert_has_api_extension"):
            a_storage_pool.save()
예제 #7
0
    def test_rename_async(self):
        add_api_extension_helper(self, ['storage'])
        a_storage_pool = models.StoragePool(self.client, name='async-lxd')
        a_volume = a_storage_pool.volumes.get('custom', 'cu1')

        _input = {"name": "vol1", "pool": "pool3", "migration": True}
        a_volume.rename(_input, wait=True)
예제 #8
0
 def test_patch(self):
     add_api_extension_helper(self, ['storage'])
     a_storage_pool = models.StoragePool(self.client, name='lxd')
     a_volume = a_storage_pool.volumes.get('custom', 'cu1')
     patch_object = {'config': {'size': 1}}
     with mock.patch.object(self.client, 'assert_has_api_extension'):
         a_volume.patch(patch_object)
예제 #9
0
 def test_patch(self):
     add_api_extension_helper(self, ["storage"])
     a_storage_pool = models.StoragePool(self.client, name="lxd")
     a_volume = a_storage_pool.volumes.get("custom", "cu1")
     patch_object = {"config": {"size": 1}}
     with mock.patch.object(self.client, "assert_has_api_extension"):
         a_volume.patch(patch_object)
예제 #10
0
    def test_rename(self):
        add_api_extension_helper(self, ['storage'])
        a_storage_pool = models.StoragePool(self.client, name='lxd')
        a_volume = a_storage_pool.volumes.get('custom', 'cu1')

        _input = {"name": "vol1", "pool": "pool3", "migration": True}
        result = a_volume.rename(_input)
        self.assertEqual(result['control'], 'secret1')
        self.assertEqual(result['fs'], 'secret2')
예제 #11
0
    def test_rename(self):
        add_api_extension_helper(self, ["storage"])
        a_storage_pool = models.StoragePool(self.client, name="lxd")
        a_volume = a_storage_pool.volumes.get("custom", "cu1")

        _input = {"name": "vol1", "pool": "pool3", "migration": True}
        result = a_volume.rename(_input)
        self.assertEqual(result["control"], "secret1")
        self.assertEqual(result["fs"], "secret2")
예제 #12
0
 def test_create_async(self):
     add_api_extension_helper(self, ['storage'])
     a_storage_pool = models.StoragePool(self.client, name='async-lxd')
     config = {
         "config": {},
         "pool": "async-lxd",
         "name": "cu1",
         "type": "custom"
     }
     a_storage_pool.volumes.create(self.client, config, wait=True)
예제 #13
0
    def test_create(self):
        a_storage_pool = models.StoragePool(self.client, name='lxd')
        config = {"config": {}, "pool": "lxd", "name": "cu1", "type": "custom"}

        # first assert that the lxd storage requires 'storage' api_extension
        with self.assertRaises(exceptions.LXDAPIExtensionNotAvailable):
            a_storage_pool.volumes.create(self.client, config)
        # now make sure that it's available without mocking it out.
        add_api_extension_helper(self, ['storage'])

        a_volume = a_storage_pool.volumes.create(self.client, config)

        self.assertEqual(config['name'], a_volume.name)
예제 #14
0
    def test_get(self):
        a_storage_pool = models.StoragePool(self.client, name='lxd')

        # first assert that the lxd storage resource requires 'resources'
        # api_extension
        with self.assertRaises(exceptions.LXDAPIExtensionNotAvailable):
            a_storage_pool.resources.get()

        # now make sure that it's available without mocking it out.
        add_api_extension_helper(self, ['resources'])
        resources = a_storage_pool.resources.get()

        self.assertEqual(resources.space['used'], 207111192576)
        self.assertEqual(resources.space['total'], 306027577344)
        self.assertEqual(resources.inodes['used'], 3275333)
        self.assertEqual(resources.inodes['total'], 18989056)
예제 #15
0
    def test_get(self):
        a_storage_pool = models.StoragePool(self.client, name='lxd')

        # first assert that the lxd storage requires 'storage' api_extension
        with self.assertRaises(exceptions.LXDAPIExtensionNotAvailable):
            a_storage_pool.volumes.get('custom', 'cu1')
        # now make sure that it's available without mocking it out.
        add_api_extension_helper(self, ['storage'])

        # now do the proper get
        volume = a_storage_pool.volumes.get('custom', 'cu1')
        self.assertEqual(volume.type, 'custom')
        self.assertEqual(volume.name, 'cu1')
        config = {
            "block.filesystem": "ext4",
            "block.mount_options": "discard",
            "size": "10737418240"
        }
        self.assertEqual(volume.config, config)
예제 #16
0
 def test_delete(self):
     add_api_extension_helper(self, ['storage'])
     a_storage_pool = models.StoragePool(self.client, name='lxd')
     a_volume = a_storage_pool.volumes.get('custom', 'cu1')
     a_volume.delete()
예제 #17
0
    def test_partial(self):
        """A partial storage_pool is synced."""
        a_storage_pool = models.StoragePool(self.client, name='lxd')

        self.assertEqual('zfs', a_storage_pool.driver)
예제 #18
0
 def test_save(self):
     add_api_extension_helper(self, ["storage"])
     a_storage_pool = models.StoragePool(self.client, name="lxd")
     a_volume = a_storage_pool.volumes.get("custom", "cu1")
     a_volume.config = {"size": 2}
     a_volume.save()
예제 #19
0
 def test_save(self):
     add_api_extension_helper(self, ['storage'])
     a_storage_pool = models.StoragePool(self.client, name='lxd')
     a_volume = a_storage_pool.volumes.get('custom', 'cu1')
     a_volume.config = {'size': 2}
     a_volume.save()
예제 #20
0
 def test_put(self):
     add_api_extension_helper(self, ['storage'])
     a_storage_pool = models.StoragePool(self.client, name='lxd')
     a_volume = a_storage_pool.volumes.get('custom', 'cu1')
     put_object = {'config': {'size': 1}}
     a_volume.put(put_object)
예제 #21
0
 def test_delete(self):
     add_api_extension_helper(self, ["storage"])
     a_storage_pool = models.StoragePool(self.client, name="lxd")
     a_volume = a_storage_pool.volumes.get("custom", "cu1")
     a_volume.delete()
예제 #22
0
    def test_save(self):
        """save is not implemented in storage_pools."""
        an_storage_pool = models.StoragePool(self.client, name='lxd')

        with self.assertRaises(NotImplementedError):
            an_storage_pool.save()
예제 #23
0
    def test_delete(self):
        """A storage pool can be deleted"""
        a_storage_pool = models.StoragePool(self.client, name='lxd')

        with mock.patch.object(self.client, 'assert_has_api_extension'):
            a_storage_pool.delete()
예제 #24
0
 def test_put(self):
     add_api_extension_helper(self, ["storage"])
     a_storage_pool = models.StoragePool(self.client, name="lxd")
     a_volume = a_storage_pool.volumes.get("custom", "cu1")
     put_object = {"config": {"size": 1}}
     a_volume.put(put_object)