File: test_share_backups.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 (152 lines) | stat: -rw-r--r-- 5,178 bytes parent folder | download
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
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
#   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 json

from manilaclient.tests.functional.osc import base


class ShareBackupCLITest(base.OSCClientTestBase):
    """Functional tests for share backup."""

    def test_share_backup_create(self):
        share = self.create_share()

        backup = self.create_backup(
            share_id=share['id'],
            name='test_backup_create',
            description='Description',
            backup_options={'dummy': True})

        # fetch latest after periodic callback updates status
        backup = json.loads(self.openstack(
            f'share backup show -f json {backup["id"]}'))

        self.assertEqual(share["id"], backup["share_id"])
        self.assertEqual('test_backup_create', backup["name"])
        self.assertEqual('Description', backup["description"])
        self.assertEqual('available', backup["status"])

        backups_list = self.listing_result('share backup', 'list')
        self.assertIn(backup['id'],
                      [item['ID'] for item in backups_list])

    def test_share_backup_delete(self):
        share = self.create_share()

        backup = self.create_backup(
            share_id=share['id'],
            backup_options={'dummy': True},
            add_cleanup=False)

        self.openstack(
            f'share backup delete {backup["id"]} --wait')

        self.check_object_deleted('share backup', backup["id"])

    def test_share_backup_show(self):
        share = self.create_share()

        backup = self.create_backup(
            share_id=share['id'],
            name='test_backup_show',
            description='Description',
            backup_options={'dummy': True})

        show_result = self.dict_result(
            'share backup', f'show {backup["id"]}')

        self.assertEqual(backup["id"], show_result["id"])
        self.assertEqual('test_backup_show', show_result["name"])
        self.assertEqual('Description', show_result["description"])

    def test_share_backup_set(self):
        share = self.create_share()

        backup = self.create_backup(share_id=share['id'],
                                    backup_options={'dummy': True})

        self.openstack(
            f'share backup set {backup["id"]} '
            f'--name test_backup_set --description Description')

        show_result = self.dict_result(
            'share backup ', f'show {backup["id"]}')

        self.assertEqual(backup['id'], show_result["id"])
        self.assertEqual('test_backup_set', show_result["name"])
        self.assertEqual('Description', show_result["description"])

    def test_share_backup_unset(self):
        share = self.create_share()

        backup = self.create_backup(
            share_id=share['id'],
            name='test_backup_unset',
            description='Description',
            backup_options={'dummy': True})

        self.openstack(
            f'share backup unset {backup["id"]} --name --description')

        show_result = json.loads(self.openstack(
            f'share backup show -f json {backup["id"]}'))

        self.assertEqual(backup['id'], show_result["id"])
        self.assertIsNone(show_result["name"])
        self.assertIsNone(show_result["description"])

    def test_share_backup_list(self):
        share_1 = self.create_share()
        share_2 = self.create_share()

        backup_1 = self.create_backup(share_id=share_1['id'],
                                      backup_options={'dummy': True})
        backup_2 = self.create_backup(share_id=share_2['id'],
                                      backup_options={'dummy': True})

        backups_list = self.listing_result(
            'share backup', f'list --name {backup_2["name"]} '
        )

        self.assertTableStruct(backups_list, [
            'ID',
            'Name',
            'Share ID',
            'Status'
        ])
        self.assertEqual(1, len(backups_list))
        self.assertIn(backup_2['id'],
                      [item['ID'] for item in backups_list])

        backups_list = self.listing_result(
            'share backup', f'list --share {share_1["id"]} --detail'
        )

        self.assertTableStruct(backups_list, [
            'ID',
            'Name',
            'Share ID',
            'Status',
            'Description',
            'Availability Zone',
            'Created At',
            'Updated At',
            'Size',
            'Progress',
            'Restore Progress',
            'Host',
            'Topic',
        ])
        self.assertEqual(1, len(backups_list))
        self.assertIn(backup_1['id'],
                      [item['ID'] for item in backups_list])