def test_grandchild_node_dir_does_not_need_to_be_owned(self): # check in /srv/node only reports one level down os.makedirs(os.path.join(self.etc_dir, 'swift')) self._create_etc_file('rsyslog.conf', content='blah') self._create_etc_file('rsyncd.conf', content='blah') bad_path1 = os.path.join(self.srv_dir, 'node', '1') bad_path2 = os.path.join(self.srv_dir, 'node', '1', 'sdb1') bad_path3 = os.path.join(self.srv_dir, 'node', '2') bad_path4 = os.path.join(self.srv_dir, 'node', '2', 'sda1') os.makedirs(bad_path2) os.makedirs(bad_path4) with mock.patch('swiftlm.swift.file_ownership.server_type', lambda x: x == ServerType.object): with mock.patch('pwd.getpwuid') as mock_pwuid: mock_pwuid.return_value = mock.Mock(pw_name='not-swift') results = FO.main() self.assertEqual(2, len(results), results) expected = [ 'Path: %s is not owned by swift' % bad_path1, 'Path: %s is not owned by swift' % bad_path3 ] for result in results: self.assertTrue(str(result) in expected) expected.remove(str(result)) self.assertFalse(expected)
def test_root_dir_does_not_need_to_be_owned(self): self._create_etc_file('rsyslog.conf', content='blah') self._create_etc_file('rsyncd.conf', content='blah') os.makedirs(os.path.join(self.etc_dir, 'swift')) os.makedirs(os.path.join(self.srv_dir, 'node')) with mock.patch('swiftlm.swift.file_ownership.server_type', lambda x: x != ServerType.object): results = FO.main() self.assertEqual(0, len(results))
def _test_missing(self, missing): results = FO.main() self.assertEqual(len(missing), len(results)) expected = [] for name in missing: expected.append('Path: %s is missing' % name) for result in results: self.assertTrue( str(result) in expected, 'result %s not in expected %s' % (result, expected)) expected.remove(str(result)) self.assertFalse(expected)
def _test_missing(self, missing): results = FO.main() self.assertEqual(len(missing), len(results)) expected = [] for name in missing: expected.append('Path: %s is missing' % name) for result in results: self.assertTrue(str(result) in expected, 'result %s not in expected %s' % (result, expected)) expected.remove(str(result)) self.assertFalse(expected)
def test_dirs_are_owned(self): self._create_etc_file('rsyslog.conf', content='blah') self._create_etc_file('rsyncd.conf', content='blah') path1 = os.path.join(self.etc_dir, 'swift', 'object-server', '1') path2 = os.path.join(self.srv_dir, 'node', '1') os.makedirs(path1) os.makedirs(path2) with mock.patch('swiftlm.swift.file_ownership.server_type', lambda x: x == ServerType.object): with mock.patch('pwd.getpwuid') as mock_pwuid: mock_pwuid.return_value = mock.Mock(pw_name='swift') results = FO.main() self.assertEqual(0, len(results))
def _test_empty(self, empty): # fake file ownership to be 'swift' with mock.patch('pwd.getpwuid') as mock_pwuid: mock_pwuid.return_value = mock.Mock(pw_name='swift') results = FO.main() self.assertEqual(len(empty), len(results), results) expected = [] for path in empty: expected.append('Path: %s should not be empty' % os.path.join(self.etc_dir, path)) for result in results: self.assertTrue( str(result) in expected, '%s not in %s' % (result, expected)) expected.remove(str(result)) self.assertFalse(expected)
def _test_empty(self, empty): # fake file ownership to be 'swift' with mock.patch('pwd.getpwuid') as mock_pwuid: mock_pwuid.return_value = mock.Mock(pw_name='swift') results = FO.main() self.assertEqual(len(empty), len(results), results) expected = [] for path in empty: expected.append( 'Path: %s should not be empty' % os.path.join(self.etc_dir, path)) for result in results: self.assertTrue(str(result) in expected, '%s not in %s' % (result, expected)) expected.remove(str(result)) self.assertFalse(expected)
def test_metrics_dirs_not_exist(self): expected = [ MetricData.single('swiftlm.swift.file_ownership.config', Severity.fail, message='dummy'), MetricData.single('swiftlm.swift.file_ownership.data', Severity.fail, message='dummy') ] with mock.patch('swiftlm.swift.file_ownership.server_type', lambda x: x == ServerType.object): with mock.patch('pwd.getpwuid') as mock_pwuid: mock_pwuid.return_value = mock.Mock(pw_name='swift') results = FO.main() self.assertEqual(len(expected), 2) same = metrics_are_similar(results, expected) self.assertEqual('', same, msg=same)
def test_grandchild_swift_dir_does_need_to_be_owned(self): self._create_etc_file('rsyslog.conf', content='blah') self._create_etc_file('rsyncd.conf', content='blah') bad_path1 = os.path.join(self.etc_dir, 'swift', 'object-server') bad_path2 = os.path.join(self.etc_dir, 'swift', 'object-server', '1') os.makedirs(bad_path2) with mock.patch('swiftlm.swift.file_ownership.server_type', lambda x: x != ServerType.object): with mock.patch('pwd.getpwuid') as mock_pwuid: mock_pwuid.return_value = mock.Mock(pw_name='not-swift') results = FO.main() self.assertEqual(2, len(results)) expected = ['Path: %s is not owned by swift' % bad_path1, 'Path: %s is not owned by swift' % bad_path2] for result in results: self.assertTrue(str(result) in expected) expected.remove(str(result)) self.assertFalse(expected)
def test_grandchild_swift_dir_does_need_to_be_owned(self): self._create_etc_file('rsyslog.conf', content='blah') self._create_etc_file('rsyncd.conf', content='blah') bad_path1 = os.path.join(self.etc_dir, 'swift', 'object-server') bad_path2 = os.path.join(self.etc_dir, 'swift', 'object-server', '1') os.makedirs(bad_path2) with mock.patch('swiftlm.swift.file_ownership.server_type', lambda x: x != ServerType.object): with mock.patch('pwd.getpwuid') as mock_pwuid: mock_pwuid.return_value = mock.Mock(pw_name='not-swift') results = FO.main() self.assertEqual(2, len(results)) expected = [ 'Path: %s is not owned by swift' % bad_path1, 'Path: %s is not owned by swift' % bad_path2 ] for result in results: self.assertTrue(str(result) in expected) expected.remove(str(result)) self.assertFalse(expected)
def test_metrics_dirs_are_owned(self): self._create_etc_file('rsyslog.conf', content='blah') self._create_etc_file('rsyncd.conf', content='blah') path1 = os.path.join(self.etc_dir, 'swift', 'object-server', '1') path2 = os.path.join(self.srv_dir, 'node', '1') os.makedirs(path1) os.makedirs(path2) expected = [ MetricData.single('swiftlm.swift.file_ownership.config', Severity.ok, message='OK'), MetricData.single('swiftlm.swift.file_ownership.data', Severity.ok, message='OK') ] with mock.patch('swiftlm.swift.file_ownership.server_type', lambda x: x == ServerType.object): with mock.patch('pwd.getpwuid') as mock_pwuid: mock_pwuid.return_value = mock.Mock(pw_name='swift') results = FO.main() self.assertEqual(len(expected), 2) same = metrics_are_same(results, expected) self.assertEqual('', same, msg=same)
def test_grandchild_node_dir_does_not_need_to_be_owned(self): # check in /srv/node only reports one level down os.makedirs(os.path.join(self.etc_dir, 'swift')) self._create_etc_file('rsyslog.conf', content='blah') self._create_etc_file('rsyncd.conf', content='blah') bad_path1 = os.path.join(self.srv_dir, 'node', '1') bad_path2 = os.path.join(self.srv_dir, 'node', '1', 'sdb1') bad_path3 = os.path.join(self.srv_dir, 'node', '2') bad_path4 = os.path.join(self.srv_dir, 'node', '2', 'sda1') os.makedirs(bad_path2) os.makedirs(bad_path4) with mock.patch('swiftlm.swift.file_ownership.server_type', lambda x: x == ServerType.object): with mock.patch('pwd.getpwuid') as mock_pwuid: mock_pwuid.return_value = mock.Mock(pw_name='not-swift') results = FO.main() self.assertEqual(2, len(results), results) expected = ['Path: %s is not owned by swift' % bad_path1, 'Path: %s is not owned by swift' % bad_path3] for result in results: self.assertTrue(str(result) in expected) expected.remove(str(result)) self.assertFalse(expected)