File: test_segment.py

package info (click to toggle)
python-openstacksdk 4.4.0-5
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 13,352 kB
  • sloc: python: 122,960; sh: 153; makefile: 23
file content (104 lines) | stat: -rw-r--r-- 4,014 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
# 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.


from openstack.network.v2 import network
from openstack.network.v2 import segment
from openstack.tests.functional import base


class TestSegment(base.BaseFunctionalTest):
    NETWORK_TYPE = None
    PHYSICAL_NETWORK = None
    SEGMENTATION_ID = None
    NETWORK_ID = None
    SEGMENT_ID = None
    SEGMENT_EXTENSION = None

    def setUp(self):
        super().setUp()
        self.NETWORK_NAME = self.getUniqueString()

        if not self.operator_cloud:
            self.skipTest("Operator cloud required for this test")

        # NOTE(rtheis): The segment extension is not yet enabled by default.
        # Skip the tests if not enabled.
        if not self.operator_cloud.network.find_extension("segment"):
            self.skipTest("Segment extension disabled")

        # Create a network to hold the segment.
        net = self.operator_cloud.network.create_network(
            name=self.NETWORK_NAME
        )
        assert isinstance(net, network.Network)
        self.assertEqual(self.NETWORK_NAME, net.name)
        self.NETWORK_ID = net.id

        if self.SEGMENT_EXTENSION:
            # Get the segment for the network.
            for seg in self.operator_cloud.network.segments():
                assert isinstance(seg, segment.Segment)
                if self.NETWORK_ID == seg.network_id:
                    self.NETWORK_TYPE = seg.network_type
                    self.PHYSICAL_NETWORK = seg.physical_network
                    self.SEGMENTATION_ID = seg.segmentation_id
                    self.SEGMENT_ID = seg.id
                    break

    def tearDown(self):
        sot = self.operator_cloud.network.delete_network(
            self.NETWORK_ID, ignore_missing=False
        )
        self.assertIsNone(sot)
        super().tearDown()

    def test_create_delete(self):
        sot = self.operator_cloud.network.create_segment(
            description="test description",
            name="test name",
            network_id=self.NETWORK_ID,
            network_type="geneve",
            segmentation_id=2055,
        )
        self.assertIsInstance(sot, segment.Segment)
        del_sot = self.operator_cloud.network.delete_segment(sot.id)
        self.assertEqual("test description", sot.description)
        self.assertEqual("test name", sot.name)
        self.assertEqual(self.NETWORK_ID, sot.network_id)
        self.assertEqual("geneve", sot.network_type)
        self.assertIsNone(sot.physical_network)
        self.assertEqual(2055, sot.segmentation_id)
        self.assertIsNone(del_sot)

    def test_find(self):
        sot = self.operator_cloud.network.find_segment(self.SEGMENT_ID)
        self.assertEqual(self.SEGMENT_ID, sot.id)

    def test_get(self):
        sot = self.operator_cloud.network.get_segment(self.SEGMENT_ID)
        self.assertEqual(self.SEGMENT_ID, sot.id)
        self.assertIsNone(sot.name)
        self.assertEqual(self.NETWORK_ID, sot.network_id)
        self.assertEqual(self.NETWORK_TYPE, sot.network_type)
        self.assertEqual(self.PHYSICAL_NETWORK, sot.physical_network)
        self.assertEqual(self.SEGMENTATION_ID, sot.segmentation_id)

    def test_list(self):
        ids = [o.id for o in self.operator_cloud.network.segments(name=None)]
        self.assertIn(self.SEGMENT_ID, ids)

    def test_update(self):
        sot = self.operator_cloud.network.update_segment(
            self.SEGMENT_ID, description="update"
        )
        self.assertEqual("update", sot.description)