Fixup py3 compatibility

This commit is contained in:
James Page 2016-09-20 14:48:30 +01:00
parent d79596ad5f
commit 7766bef0b9
7 changed files with 53 additions and 42 deletions

View File

@ -12,6 +12,7 @@
# See the License for the specific language governing permissions and
# limitations under the License.
import ctypes
import collections
import json
import random
import socket
@ -54,7 +55,8 @@ LEADER = 'leader'
PEON = 'peon'
QUORUM = [LEADER, PEON]
PACKAGES = ['ceph', 'gdisk', 'ntp', 'btrfs-tools', 'python-ceph', 'radosgw', 'xfsprogs']
PACKAGES = ['ceph', 'gdisk', 'ntp', 'btrfs-tools', 'python-ceph',
'radosgw', 'xfsprogs']
LinkSpeed = {
"BASE_10": 10,
@ -934,36 +936,36 @@ def get_mds_key(name):
caps=mds_caps)
_default_caps = {
'mon': ['allow rw'],
'osd': ['allow rwx']
}
_default_caps = collections.OrderedDict([
('mon', ['allow rw']),
('osd', ['allow rwx']),
])
admin_caps = {
'mds': ['allow *'],
'mon': ['allow *'],
'osd': ['allow *']
}
admin_caps = collections.OrderedDict([
('mds', ['allow *']),
('mon', ['allow *']),
('osd', ['allow *'])
])
mds_caps = {
'osd': ['allow *'],
'mds': ['allow'],
'mon': ['allow rwx'],
}
mds_caps = collections.OrderedDict([
('osd', ['allow *']),
('mds', ['allow']),
('mon', ['allow rwx']),
])
osd_upgrade_caps = {
'mon': ['allow command "config-key"',
'allow command "osd tree"',
'allow command "config-key list"',
'allow command "config-key put"',
'allow command "config-key get"',
'allow command "config-key exists"',
'allow command "osd out"',
'allow command "osd in"',
'allow command "osd rm"',
'allow command "auth del"',
]
}
osd_upgrade_caps = collections.OrderedDict([
('mon', ['allow command "config-key"',
'allow command "osd tree"',
'allow command "config-key list"',
'allow command "config-key put"',
'allow command "config-key get"',
'allow command "config-key exists"',
'allow command "osd out"',
'allow command "osd in"',
'allow command "osd rm"',
'allow command "auth del"',
])
])
def create_named_keyring(entity, name, caps=None):
@ -981,7 +983,7 @@ def create_named_keyring(entity, name, caps=None):
'auth', 'get-or-create', '{entity}.{name}'.format(entity=entity,
name=name),
]
for subsystem, subcaps in caps.iteritems():
for subsystem, subcaps in caps.items():
cmd.extend([subsystem, '; '.join(subcaps)])
log("Calling subprocess.check_output: {}".format(cmd), level=DEBUG)
return parse_key(subprocess.check_output(cmd).strip()) # IGNORE:E1103
@ -1013,7 +1015,7 @@ def get_named_key(name, caps=None, pool_list=None):
'auth', 'get-or-create', 'client.{}'.format(name),
]
# Add capabilities
for subsystem, subcaps in caps.iteritems():
for subsystem, subcaps in caps.items():
if subsystem == 'osd':
if pool_list:
# This will output a string similar to:
@ -1033,7 +1035,7 @@ def upgrade_key_caps(key, caps):
cmd = [
"sudo", "-u", ceph_user(), 'ceph', 'auth', 'caps', key
]
for subsystem, subcaps in caps.iteritems():
for subsystem, subcaps in caps.items():
cmd.extend([subsystem, '; '.join(subcaps)])
subprocess.check_call(cmd)

View File

@ -60,8 +60,8 @@ POOL_KEYS = {
"write_fadvise_dontneed": [bool],
"noscrub": [bool],
"nodeep-scrub": [bool],
"hit_set_type": [basestring, ["bloom", "explicit_hash",
"explicit_object"]],
"hit_set_type": [str, ["bloom", "explicit_hash",
"explicit_object"]],
"hit_set_count": [int, [1, 1]],
"hit_set_period": [int],
"hit_set_fpp": [float, [0.0, 1.0]],

View File

@ -5,6 +5,5 @@ coverage>=3.6
mock>=1.2
flake8>=2.2.4,<=2.4.1
os-testr>=0.4.1
charm-tools>=2.0.0
requests==2.6.0
netifaces

12
tox.ini
View File

@ -1,5 +1,5 @@
[tox]
envlist = pep8,py27
envlist = pep8,py27,py34,py35
skipsdist = True
[testenv]
@ -15,6 +15,16 @@ basepython = python2.7
deps = -r{toxinidir}/requirements.txt
-r{toxinidir}/test-requirements.txt
[testenv:py34]
basepython = python3.4
deps = -r{toxinidir}/requirements.txt
-r{toxinidir}/test-requirements.txt
[testenv:py35]
basepython = python3.5
deps = -r{toxinidir}/requirements.txt
-r{toxinidir}/test-requirements.txt
[testenv:pep8]
basepython = python2.7
deps = -r{toxinidir}/requirements.txt

View File

@ -15,7 +15,7 @@
import mock
import unittest
import ceph.ceph as ceph
import ceph
class CephTestCase(unittest.TestCase):
@ -26,7 +26,7 @@ class CephTestCase(unittest.TestCase):
with mock.patch.object(ceph, "ceph_user", return_value="ceph"):
with mock.patch.object(ceph.subprocess, "check_output") \
as subprocess:
with mock.patch.object(ceph, "get_unit_hostname",
with mock.patch.object(ceph.socket, "gethostname",
return_value="osd001"):
ceph.get_named_key(name="rgw001",
pool_list=["rbd", "block"])
@ -43,7 +43,7 @@ class CephTestCase(unittest.TestCase):
with mock.patch.object(ceph, "ceph_user", return_value="ceph"):
with mock.patch.object(ceph.subprocess, "check_output") \
as subprocess:
with mock.patch.object(ceph, "get_unit_hostname",
with mock.patch.object(ceph.socket, "gethostname",
return_value="osd001"):
ceph.get_named_key(name="rgw001")
subprocess.assert_called_with(

View File

@ -41,7 +41,6 @@ class CephBrokerTestCase(unittest.TestCase):
def test_process_requests_invalid_api_version(self, mock_log):
req = json.dumps({'api-version': 2, 'ops': []})
rc = ceph_broker.process_requests(req)
print "Return: %s" % rc
self.assertEqual(json.loads(rc),
{'exit-code': 1,
'stderr': 'Missing or invalid api version (2)'})

View File

@ -55,7 +55,7 @@ class UpgradeRollingTestCase(unittest.TestCase):
@patch('ceph.upgrade_monitor')
@patch('ceph.monitor_key_set')
def test_lock_and_roll(self, monitor_key_set, upgrade_monitor, log, time):
time.return_value = 1473279502.688828
time.return_value = 1473279502.69
monitor_key_set.monitor_key_set.return_value = None
ceph.lock_and_roll(my_name='ip-192-168-1-2',
version='0.94.1',
@ -67,7 +67,9 @@ class UpgradeRollingTestCase(unittest.TestCase):
call('monitor_key_set '
'mon_ip-192-168-1-2_0.94.1_start 1473279502.69'),
call('Rolling'),
call('Done')
call('Done'),
call('monitor_key_set '
'mon_ip-192-168-1-2_0.94.1_done 1473279502.69'),
])
@patch('ceph.apt_install')
@ -87,7 +89,6 @@ class UpgradeRollingTestCase(unittest.TestCase):
local_mons, add_source, apt_update, status_set,
log, service_start, service_stop, chownr,
apt_install):
print "Upgrading monitor"
get_version.return_value = "0.80"
config.side_effect = config_side_effect
ceph_user.return_value = "ceph"