~ubuntu-branches/ubuntu/quantal/quantum/quantal-proposed

« back to all changes in this revision

Viewing changes to quantum/tests/unit/nec/test_pfc_driver.py

  • Committer: Package Import Robot
  • Author(s): Adam Gandelman
  • Date: 2013-04-25 17:52:50 UTC
  • mfrom: (2.1.18)
  • Revision ID: package-import@ubuntu.com-20130425175250-411niboa5hpszqzl
Tags: 2012.2.4-0ubuntu1
* Resynchronize with stable/folsom (96680c96) (LP: #1179707):
  - [527b5ec] Folsom NEC plugin fails to create a network/port on some version
    of PFC due to too long string LP: 1166077
  - [346aae3] Folsom NEC plugin: Cannot create a tenant on some version of
    OpenFlow controller LP: 1166076
  - [a31069a] Network cannot be created in NEC plugin when OFC network ID is
    unique inside a tenant LP: 1127664
  - [a109f7e] Folsom l3 agent unable to connect to quantum service LP: 1157090
  - [913586b] MyISAM does not perform cascading deletions LP: 1153594
  - [5a2ef81] Openstack quantum, race condition in ip address creation when
    starting 50 VMs on a 5-node cluster LP: 1110807
  - [f94b149] Deleting a subnet that is added to a router leaves behind a port
    that cannot be deleted LP: 1104337
  - [b14824f] Address re-allocation before DHCP lease's expire LP: 1116500
  - [30bb632] file descriptors not closed when executing sub-processes
    LP: 1130735
  - [5d26f41] DHCP agent could take upto a minute to get its IP address
    LP: 1128180
  - [2f32795] dhcp-agent distributes empty domain when dhcp_domain=""
    LP: 1099625
  - [8755cb3] ovs and netns cleanupo utilities do not log LP: 1118517
  - [45baf03] l3_agent destroys all namespaces on init, even if router_id is
    set (LP: #1122206)

Show diffs side-by-side

added added

removed removed

Lines of Context:
15
15
#    under the License.
16
16
# @author: Ryota MIBU
17
17
 
 
18
import random
 
19
import string
 
20
 
18
21
import mox
19
22
import unittest
20
23
 
33
36
    cert_file = None
34
37
 
35
38
 
36
 
def _ofc(id):
 
39
def _ofc(val):
37
40
    """OFC ID converter"""
38
 
    return "ofc-%s" % id
 
41
    vals = val.split('-')
 
42
    vals[2] = vals[2][1:]
 
43
    return ''.join(vals)
 
44
 
 
45
 
 
46
def _ofc_desc(val):
 
47
    """OFC description converter (replace hyphen and space to underscore)"""
 
48
    return val.replace('-', '_').replace(' ', '_')[:127]
39
49
 
40
50
 
41
51
class PFCDriverTestBase(unittest.TestCase):
63
73
        description = "desc of %s" % t
64
74
 
65
75
        path = "/tenants"
66
 
        body = {'id': t, 'description': description}
67
 
        tenant = {'id': _ofc(t)}
 
76
        body = {'id': _ofc(t)}
 
77
        tenant = {}
68
78
        ofc.OFCClient.do_request("POST", path, body=body).AndReturn(tenant)
69
79
        self.mox.ReplayAll()
70
80
 
72
82
        self.mox.VerifyAll()
73
83
        self.assertEqual(ret, _ofc(t))
74
84
 
75
 
    def testb_update_tenant(self):
76
 
        t, n, p = self.get_ofc_item_random_params()
77
 
        description = "new desc of %s" % t
78
 
 
79
 
        path = "/tenants/%s" % _ofc(t)
80
 
        body = {'description': description}
81
 
        ofc.OFCClient.do_request("PUT", path, body=body)
82
 
        self.mox.ReplayAll()
83
 
 
84
 
        self.driver.update_tenant(_ofc(t), description)
85
 
        self.mox.VerifyAll()
86
 
 
87
85
    def testc_delete_tenant(self):
88
86
        t, n, p = self.get_ofc_item_random_params()
89
87
 
99
97
        description = "desc of %s" % n
100
98
 
101
99
        path = "/tenants/%s/networks" % _ofc(t)
102
 
        body = {'id': n, 'description': description}
103
 
        network = {'id': _ofc(n)}
 
100
        body = {'id': _ofc(n), 'description': _ofc_desc(description)}
 
101
        network = {}
104
102
        ofc.OFCClient.do_request("POST", path, body=body).AndReturn(network)
105
103
        self.mox.ReplayAll()
106
104
 
113
111
        description = "desc of %s" % n
114
112
 
115
113
        path = "/tenants/%s/networks/%s" % (_ofc(t), _ofc(n))
116
 
        body = {'description': description}
 
114
        body = {'description': _ofc_desc(description)}
117
115
        ofc.OFCClient.do_request("PUT", path, body=body)
118
116
        self.mox.ReplayAll()
119
117
 
134
132
        t, n, p = self.get_ofc_item_random_params()
135
133
 
136
134
        path = "/tenants/%s/networks/%s/ports" % (_ofc(t), _ofc(n))
137
 
        body = {'id': p.id,
 
135
        body = {'id': _ofc(p.id),
138
136
                'datapath_id': p.datapath_id,
139
137
                'port': str(p.port_no),
140
138
                'vid': str(p.vlan_id)}
141
 
        port = {'id': _ofc(p.id)}
 
139
        port = {}
142
140
        ofc.OFCClient.do_request("POST", path, body=body).AndReturn(port)
143
141
        self.mox.ReplayAll()
144
142
 
156
154
 
157
155
        self.driver.delete_port(_ofc(t), _ofc(n), _ofc(p.id))
158
156
        self.mox.VerifyAll()
 
157
 
 
158
 
 
159
class PFCDriverStringTest(unittest.TestCase):
 
160
 
 
161
    driver = 'quantum.plugins.nec.drivers.pfc.PFCDriverBase'
 
162
 
 
163
    def setUp(self):
 
164
        super(PFCDriverStringTest, self).setUp()
 
165
        self.driver = drivers.get_driver("pfc")(TestConfig)
 
166
 
 
167
    def test_generate_pfc_id_uuid(self):
 
168
        id_str = utils.str_uuid()
 
169
        exp_str = (id_str[:14] + id_str[15:]).replace('-', '')[:31]
 
170
 
 
171
        ret_str = self.driver._generate_pfc_id(id_str)
 
172
        self.assertEqual(exp_str, ret_str)
 
173
 
 
174
    def test_generate_pfc_id_uuid_no_hyphen(self):
 
175
        # Keystone tenant_id style uuid
 
176
        id_str = utils.str_uuid()
 
177
        id_no_hyphen = id_str.replace('-', '')
 
178
        exp_str = (id_str[:14] + id_str[15:]).replace('-', '')[:31]
 
179
 
 
180
        ret_str = self.driver._generate_pfc_id(id_no_hyphen)
 
181
        self.assertEqual(exp_str, ret_str)
 
182
 
 
183
    def test_generate_pfc_id_string(self):
 
184
        id_str = utils.str_uuid() + 'x'
 
185
        exp_str = id_str[:31].replace('-', '_')
 
186
 
 
187
        ret_str = self.driver._generate_pfc_id(id_str)
 
188
        self.assertEqual(exp_str, ret_str)
 
189
 
 
190
    def test_generate_pfc_desc(self):
 
191
        random_list = [random.choice(string.printable) for x in range(128)]
 
192
        random_str = ''.join(random_list)
 
193
 
 
194
        accept_letters = string.letters + string.digits
 
195
        exp_list = [x if x in accept_letters else '_' for x in random_list]
 
196
        exp_str = ''.join(exp_list)[:127]
 
197
 
 
198
        ret_str = self.driver._generate_pfc_description(random_str)
 
199
        self.assertEqual(exp_str, ret_str)