File: test_snapshot_instances_export_locations.py

package info (click to toggle)
python-manilaclient 5.4.0-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 3,768 kB
  • sloc: python: 49,541; makefile: 99; sh: 2
file content (117 lines) | stat: -rw-r--r-- 4,634 bytes parent folder | download | duplicates (3)
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
# Copyright (c) 2017 Hitachi Data Systems
# 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 and
                      CONF.run_mount_snapshot_tests,
                      "Snapshots or mountable snapshots tests are disabled.")
@utils.skip_if_microversion_not_supported('2.32')
class SnapshotInstanceExportLocationReadWriteTest(base.BaseTestCase):

    def setUp(self):
        super(SnapshotInstanceExportLocationReadWriteTest, 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_get_snapshot_instance_export_location(self):
        client = self.admin_client
        snapshot_instances = client.list_snapshot_instances(
            self.snapshot['id'])

        self.assertGreater(len(snapshot_instances), 0)
        self.assertIn('ID', snapshot_instances[0])
        self.assertTrue(uuidutils.is_uuid_like(
            snapshot_instances[0]['ID']))

        snapshot_instance_id = snapshot_instances[0]['ID']

        export_locations = client.list_snapshot_instance_export_locations(
            snapshot_instance_id)

        el = client.get_snapshot_instance_export_location(
            snapshot_instance_id, export_locations[0]['ID'])
        expected_keys = ['path', 'id', 'is_admin_only',
                         'share_snapshot_instance_id', 'updated_at',
                         'created_at']

        for key in expected_keys:
            self.assertIn(key, el)
        for key, key_el in (
                ('ID', 'id'), ('Path', 'path'),
                ('Is Admin only', 'is_admin_only')):
            self.assertEqual(export_locations[0][key], el[key_el])
        self.assertTrue(uuidutils.is_uuid_like(
            el['share_snapshot_instance_id']))
        self.assertTrue(uuidutils.is_uuid_like(el['id']))
        self.assertIn(el['is_admin_only'], ('True', 'False'))

    def test_list_snapshot_instance_export_locations(self):
        client = self.admin_client
        snapshot_instances = client.list_snapshot_instances(
            self.snapshot['id'])

        self.assertGreater(len(snapshot_instances), 0)
        self.assertIn('ID', snapshot_instances[0])
        self.assertTrue(uuidutils.is_uuid_like(snapshot_instances[0]['ID']))

        snapshot_instance_id = snapshot_instances[0]['ID']

        export_locations = client.list_snapshot_instance_export_locations(
            snapshot_instance_id)

        self.assertGreater(len(export_locations), 0)

        expected_keys = ('ID', 'Path', 'Is Admin only')
        for el in export_locations:
            for key in expected_keys:
                self.assertIn(key, el)
            self.assertTrue(uuidutils.is_uuid_like(el['ID']))

    def test_list_snapshot_instance_export_locations_with_columns(self):
        client = self.admin_client
        snapshot_instances = client.list_snapshot_instances(
            self.snapshot['id'])

        self.assertGreater(len(snapshot_instances), 0)
        self.assertIn('ID', snapshot_instances[0])
        self.assertTrue(uuidutils.is_uuid_like(snapshot_instances[0]['ID']))
        snapshot_instance_id = snapshot_instances[0]['ID']

        export_locations = client.list_snapshot_instance_export_locations(
            snapshot_instance_id, columns='id,path')

        self.assertGreater(len(export_locations), 0)
        expected_keys = ('Id', 'Path')
        unexpected_keys = ('Updated At', 'Created At', 'Is Admin only')

        for el in export_locations:
            for key in expected_keys:
                self.assertIn(key, el)
            for key in unexpected_keys:
                self.assertNotIn(key, el)
            self.assertTrue(uuidutils.is_uuid_like(el['Id']))