Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
import pytest
import salt.client
import os
from pyfakefs import fake_filesystem, fake_filesystem_glob
from mock import patch, MagicMock
import mock
from srv.modules.runners import ui_rgw
fs = fake_filesystem.FakeFilesystem()
f_glob = fake_filesystem_glob.FakeGlobModule(fs)
f_os = fake_filesystem.FakeOsModule(fs)
f_open = fake_filesystem.FakeFileOpen(fs)
class TestRadosgw():
@patch('salt.client.LocalClient', autospec=True)
@patch('salt.utils.master.MasterPillarUtil', autospec=True)
@patch('os.path.exists', new=f_os.path.exists)
@patch('__builtin__.open', new=f_open)
@patch('glob.glob', new=f_glob.glob)
def test_admin(self, masterpillarutil, localclient):
result = {'urls': [],
'access_key': '12345',
'secret_key': 'abcdef',
'user_id': 'admin',
'success': True}
import pytest
import salt.client
import os
import sys
sys.path.insert(0, 'srv/salt/_modules')
from pyfakefs import fake_filesystem, fake_filesystem_glob
from mock import patch, MagicMock, mock
from srv.salt._modules import subvolume
fs = fake_filesystem.FakeFilesystem()
f_glob = fake_filesystem_glob.FakeGlobModule(fs)
f_os = fake_filesystem.FakeOsModule(fs)
f_open = fake_filesystem.FakeFileOpen(fs)
class Testsubvolume():
@patch('srv.salt._modules.subvolume._btrfs')
def test_check_mounted(self, mockb):
mockb.return_value = [True, True]
state, msg = subvolume.check()
assert state == True
assert msg == "/var/lib/ceph subvolume mounted"
@patch('srv.salt._modules.subvolume._btrfs')
def test_check_not_btrfs(self, mockb):
mockb.return_value = [False, False]
state, msg = subvolume.check()
import pytest
import salt.client
import os
import sys
sys.path.insert(0, 'srv/salt/_modules')
from pyfakefs import fake_filesystem, fake_filesystem_glob
from mock import patch, MagicMock
from srv.salt._modules import rgw
fs = fake_filesystem.FakeFilesystem()
f_glob = fake_filesystem_glob.FakeGlobModule(fs)
f_os = fake_filesystem.FakeOsModule(fs)
f_open = fake_filesystem.FakeFileOpen(fs)
class TestRadosgw():
pass
class TestOSDInstanceMethods():
'''
This class contains a set of functions that test srv.salt._modules.osd
'''
fs = fake_fs.FakeFilesystem()
dev_dir = '/dev'
devices = ['sda', 'sdaa', 'sda1', 'sda10', 'sdaa1', 'sdaa10',
'sdax', 'sdax10',
'nvme0n1', 'nvme1n1', 'nvme100n1', 'nvme0n1p1',
'nvme0n1p100', 'nvme0n100', 'nvme1n1p1', 'nvme100n1p1']
for dev in devices:
fs.CreateFile('{}/{}'.format(dev_dir, dev))
f_glob = fake_glob.FakeGlobModule(fs)
f_os = fake_fs.FakeOsModule(fs)
f_open = fake_fs.FakeFileOpen(fs)
@mock.patch('srv.salt._modules.osd.glob')
def test_devices(self, glob):
glob.return_value.glob = []
ret = osd.devices()
glob.glob.assert_called_once()
glob.glob.assert_called_with('/var/lib/ceph/osd/*')
assert type(ret) is list
@mock.patch('srv.salt._modules.osd.glob')
def test_pairs(self, glob):
glob.return_value.glob = []
ret = osd.pairs()
glob.glob.assert_called_once()
contents='cluster-ceph/cluster/*.sls \t# with a comment')
fs.CreateFile('policy.cfg_ml_commented',
contents=('# a line comment\n'
'cluster-ceph/cluster/*.sls \t# with a comment'))
fs.CreateFile('policy.cfg_leading_whitespace',
contents=(' cluster-ceph/cluster/*.sls'))
fs.CreateFile('policy.cfg_trailing_whitespace',
contents=('cluster-ceph/cluster/*.sls '))
fs.CreateFile('policy.cfg_trailing_and_leading_whitespace',
contents=(' cluster-ceph/cluster/*.sls '))
fs.CreateFile('policy.cfg_trailing_and_leading_whitespace_and_leading_comment',
contents=(' #cluster-ceph/cluster/*.sls '))
fs.CreateFile('policy.cfg_trailing_and_leading_whitespace_and_trailing_comment',
contents=(' cluster-ceph/cluster/*.sls #'))
f_glob = fake_glob.FakeGlobModule(fs)
f_os = fake_fs.FakeOsModule(fs)
f_open = fake_fs.FakeFileOpen(fs)
class TestPush():
@patch('glob.glob', new=f_glob.glob)
def test_parse(self):
parsed = push._parse('{}/*.sls'.format(proposal_dir))
assert len(parsed) == len(nodes)
parsed = push._parse('{}/mon*.sls'.format(proposal_dir))
assert len(parsed) == len([n for n in nodes if n.startswith('mon')])
parsed = push._parse('{}/mon[1,2].sls'.format(proposal_dir))
import pytest
import salt.client
import os
from pyfakefs import fake_filesystem, fake_filesystem_glob
from mock import patch, MagicMock
from srv.modules.runners import ui_iscsi
fs = fake_filesystem.FakeFilesystem()
f_glob = fake_filesystem_glob.FakeGlobModule(fs)
f_os = fake_filesystem.FakeOsModule(fs)
f_open = fake_filesystem.FakeFileOpen(fs)
class TestIscsi():
@patch('salt.client.LocalClient', autospec=True)
@patch('srv.modules.runners.ui_iscsi.Iscsi.config', autospec=True)
@patch('srv.modules.runners.ui_iscsi.Iscsi.interfaces', autospec=True)
@patch('srv.modules.runners.ui_iscsi.Iscsi.images', autospec=True)
def test_populate(self, localclient, config, interfaces, images):
iscsi = ui_iscsi.Iscsi()
result = iscsi.populate()
assert (config.call_count == 1 and 'config' in result and
interfaces.call_count == 1 and 'interfaces' in result and
images.call_count == 1 and 'images' in result)
def _RunDoctest():
# pylint: disable=import-self
import doctest
from pyfakefs import fake_filesystem_glob
return doctest.testmod(fake_filesystem_glob)