Browse code

Add %check for python-etcd

Added fix as mentioned in
https://github.com/jplana/python-etcd/commit/7f3dd65e5dc79cc456ef58a052501ec256d5070b
for test failure
https://github.com/jplana/python-etcd/issues/210

Change-Id: Id8fbdc48dc4115b8790ad10486833b2dfca246a2
Reviewed-on: http://photon-jenkins.eng.vmware.com:8082/6289
Tested-by: michellew <michellew@vmware.com>
Reviewed-by: Sharath George

ashwin-h authored on 2018/12/05 05:14:31
Showing 2 changed files
1 1
new file mode 100644
... ...
@@ -0,0 +1,75 @@
0
+commit 7f3dd65e5dc79cc456ef58a052501ec256d5070b
1
+Author: Giuseppe Lavagetto <lavagetto@gmail.com>
2
+Date:   Mon Feb 13 14:12:39 2017 +0100
3
+
4
+    Support auth API both <= 2.2.5 and >= 2.3.0
5
+    
6
+    Closes #210
7
+
8
+diff --git a/src/etcd/auth.py b/src/etcd/auth.py
9
+index 796772d..c5c7346 100644
10
+--- a/src/etcd/auth.py
11
+@@ -14,13 +14,28 @@ class EtcdAuthBase(object):
12
+         self.name = name
13
+         self.uri = "{}/auth/{}s/{}".format(self.client.version_prefix,
14
+                                            self.entity, self.name)
15
++        # This will be lazily evaluated if not manually set
16
++        self._legacy_api = None
17
++
18
++    @property
19
++    def legacy_api(self):
20
++        if self._legacy_api is None:
21
++            # The auth API has changed between 2.2 and 2.3, true story!
22
++            major, minor, _ = map(int, self.client.version.split('.'))
23
++            self._legacy_api = (major < 3 and minor < 3)
24
++        return self._legacy_api
25
++
26
+ 
27
+     @property
28
+     def names(self):
29
+         key = "{}s".format(self.entity)
30
+         uri = "{}/auth/{}".format(self.client.version_prefix, key)
31
+         response = self.client.api_execute(uri, self.client._MGET)
32
+-        return json.loads(response.data.decode('utf-8'))[key]
33
++        if self.legacy_api:
34
++            return json.loads(response.data.decode('utf-8'))[key]
35
++        else:
36
++            return [obj[self.entity]
37
++                    for obj in json.loads(response.data.decode('utf-8'))[key]]
38
+ 
39
+     def read(self):
40
+         try:
41
+@@ -102,7 +117,16 @@ class EtcdUser(EtcdAuthBase):
42
+ 
43
+     def _from_net(self, data):
44
+         d = json.loads(data.decode('utf-8'))
45
+-        self.roles = d.get('roles', [])
46
++        roles = d.get('roles', [])
47
++        try:
48
++            self.roles = roles
49
++        except TypeError:
50
++            # with the change of API, PUT responses are different
51
++            # from GET reponses, which makes everything so funny.
52
++            # Specifically, PUT responses are the same as before...
53
++            if self.legacy_api:
54
++                raise
55
++            self.roles = [obj['role'] for obj in roles]
56
+         self.name = d.get('user')
57
+ 
58
+     def _to_net(self, prevobj=None):
59
+diff --git a/src/etcd/tests/test_auth.py b/src/etcd/tests/test_auth.py
60
+index 14475f9..5c8c0b0 100644
61
+--- a/src/etcd/tests/test_auth.py
62
+@@ -93,6 +93,10 @@ class EtcdUserTest(TestEtcdAuthBase):
63
+         self.assertEquals(u.roles, set(['guest', 'root']))
64
+         # set roles as a list, it works!
65
+         u.roles = ['guest', 'test_group']
66
++        # We need this or the new API will return an internal error
67
++        r = auth.EtcdRole(self.client, 'test_group')
68
++        r.acls = {'*': 'R', '/test/*': 'RW'}
69
++        r.write()
70
+         try:
71
+             u.write()
72
+         except:
... ...
@@ -3,12 +3,13 @@
3 3
 
4 4
 Name:           python-etcd
5 5
 Version:        0.4.5
6
-Release:        1%{?dist}
6
+Release:        2%{?dist}
7 7
 Summary:        Python API for etcd
8 8
 License:        MIT
9 9
 Group:          Development/Languages/Python
10 10
 Url:            https://pypi.python.org/pypi/python-etcd
11 11
 Source0:        %{name}-%{version}.tar.gz
12
+Patch0:         auth-api-compatibility.patch
12 13
 %define sha1    python-etcd=9e79ae82429cf2ffbe2b5647e14bc29571afd766
13 14
 Vendor:         VMware, Inc.
14 15
 Distribution:   Photon
... ...
@@ -18,6 +19,15 @@ BuildRequires:  python2-devel
18 18
 BuildRequires:  python2-libs
19 19
 BuildRequires:  python-pip
20 20
 BuildRequires:  python-setuptools
21
+%if %{with_check}
22
+BuildRequires:  python-dnspython
23
+BuildRequires:  python-urllib3
24
+BuildRequires:  python-pyOpenSSL
25
+BuildRequires:  etcd
26
+BuildRequires:  openssl-devel
27
+BuildRequires:  curl-devel
28
+BuildRequires:  libffi-devel
29
+%endif
21 30
 Requires:       python2
22 31
 Requires:       python2-libs
23 32
 Requires:       python-setuptools
... ...
@@ -33,12 +43,18 @@ BuildRequires:  python3-devel
33 33
 BuildRequires:  python3-libs
34 34
 BuildRequires:  python3-pip
35 35
 BuildRequires:  python3-setuptools
36
+%if %{with_check}
37
+BuildRequires:  python3-dnspython
38
+BuildRequires:  python3-urllib3
39
+BuildRequires:  python3-pyOpenSSL
40
+%endif
36 41
 
37 42
 %description -n python3-etcd
38 43
 Python3 API for etcd
39 44
 
40 45
 %prep
41 46
 %setup -n %{name}-%{version}
47
+%patch0 -p1
42 48
 rm -rf ../p3dir
43 49
 cp -a . ../p3dir
44 50
 
... ...
@@ -54,6 +70,14 @@ python3 setup.py install --prefix=%{_prefix} --root=%{buildroot}
54 54
 popd
55 55
 python2 setup.py install --prefix=%{_prefix} --root=%{buildroot}
56 56
 
57
+%check
58
+easy_install_2=$(ls /usr/bin |grep easy_install |grep 2)
59
+$easy_install_2 nose
60
+python2 setup.py test
61
+easy_install_3=$(ls /usr/bin |grep easy_install |grep 3)
62
+$easy_install_3 nose
63
+python3 setup.py test
64
+
57 65
 %files
58 66
 %defattr(-,root,root,-)
59 67
 %{python2_sitelib}/*
... ...
@@ -63,5 +87,7 @@ python2 setup.py install --prefix=%{_prefix} --root=%{buildroot}
63 63
 %{python3_sitelib}/*
64 64
 
65 65
 %changelog
66
+*   Tue Dec 04 2018 Ashwin H<ashwinh@vmware.com> 0.4.5-2
67
+-   Add %check
66 68
 *   Sat Aug 26 2017 Vinay Kulkarni <kulkarniv@vmware.com> 0.4.5-1
67 69
 -   Initial version of python etcd for PhotonOS.