1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119
|
# Copyright 2016 Huawei inc.
# All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License"); you may
# not use this file except in compliance with the License. You may obtain
# a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations
# under the License.
import ddt
from oslo_utils import uuidutils
import testtools
from manilaclient import config
from manilaclient.tests.functional import base
from manilaclient.tests.functional import utils
CONF = config.CONF
@ddt.ddt
@testtools.skipUnless(CONF.run_snapshot_tests,
'Snapshot tests disabled.')
@utils.skip_if_microversion_not_supported('2.19')
class SnapshotInstancesTest(base.BaseTestCase):
def setUp(self):
super(SnapshotInstancesTest, self).setUp()
self.share = self.create_share(
client=self.get_user_client())
self.snapshot = self.create_snapshot(share=self.share['id'],
client=self.get_user_client())
def test_list_all_snapshot_instances(self):
snapshot_instances = self.admin_client.list_snapshot_instances()
self.assertGreater(len(snapshot_instances), 0)
expected_keys = ('ID', 'Snapshot ID', 'Status')
for si in snapshot_instances:
for key in expected_keys:
self.assertIn(key, si)
self.assertTrue(uuidutils.is_uuid_like(si['ID']))
self.assertTrue(uuidutils.is_uuid_like(si['Snapshot ID']))
def test_list_all_snapshot_instances_details(self):
snapshot_instances = self.admin_client.list_snapshot_instances(
detailed=True)
self.assertGreater(len(snapshot_instances), 0)
expected_keys = ('ID', 'Snapshot ID', 'Status', 'Created_at',
'Updated_at', 'Share_id', 'Share_instance_id',
'Progress', 'Provider_location')
for si in snapshot_instances:
for key in expected_keys:
self.assertIn(key, si)
for key in ('ID', 'Snapshot ID', 'Share_id', 'Share_instance_id'):
self.assertTrue(
uuidutils.is_uuid_like(si[key]))
def test_list_snapshot_instance_with_snapshot(self):
snapshot_instances = self.admin_client.list_snapshot_instances(
snapshot_id=self.snapshot['id'])
self.assertEqual(1, len(snapshot_instances))
expected_keys = ('ID', 'Snapshot ID', 'Status')
for si in snapshot_instances:
for key in expected_keys:
self.assertIn(key, si)
self.assertTrue(uuidutils.is_uuid_like(si['ID']))
self.assertTrue(uuidutils.is_uuid_like(si['Snapshot ID']))
def test_list_snapshot_instance_with_columns(self):
snapshot_instances = self.admin_client.list_snapshot_instances(
self.snapshot['id'], columns='id,status')
self.assertGreater(len(snapshot_instances), 0)
expected_keys = ('Id', 'Status')
unexpected_keys = ('Snapshot ID', )
for si in snapshot_instances:
for key in expected_keys:
self.assertIn(key, si)
for key in unexpected_keys:
self.assertNotIn(key, si)
self.assertTrue(uuidutils.is_uuid_like(si['Id']))
def test_get_snapshot_instance(self):
snapshot_instances = self.admin_client.list_snapshot_instances(
self.snapshot['id'])
snapshot_instance = self.admin_client.get_snapshot_instance(
snapshot_instances[0]['ID'])
self.assertGreater(len(snapshot_instance), 0)
expected_keys = ('id', 'snapshot_id', 'status', 'created_at',
'updated_at', 'share_id', 'share_instance_id',
'progress', 'provider_location')
for key in expected_keys:
self.assertIn(key, snapshot_instance)
for key in ('id', 'snapshot_id', 'share_id', 'share_instance_id'):
self.assertTrue(
uuidutils.is_uuid_like(snapshot_instance[key]))
def test_snapshot_instance_reset_state(self):
snapshot_instances = self.admin_client.list_snapshot_instances(
self.snapshot['id'])
self.admin_client.reset_snapshot_instance(
snapshot_instances[0]['ID'], 'error')
snapshot_instance = self.admin_client.get_snapshot_instance(
snapshot_instances[0]['ID'])
self.assertEqual('error', snapshot_instance['status'])
self.admin_client.reset_snapshot_instance(snapshot_instance['id'],
'available')
|