Merge " Add 'virsh-audit' action in nova-compute"
This commit is contained in:
commit
203140252c
@ -26,3 +26,5 @@ hugepagereport:
|
|||||||
description: Report on hugepage configuration and usage
|
description: Report on hugepage configuration and usage
|
||||||
security-checklist:
|
security-checklist:
|
||||||
description: Validate the running configuration against the OpenStack security guides checklist
|
description: Validate the running configuration against the OpenStack security guides checklist
|
||||||
|
virsh-audit:
|
||||||
|
description: List all domains as virsh sees on the compute node
|
1
actions/virsh-audit
Symbolic link
1
actions/virsh-audit
Symbolic link
@ -0,0 +1 @@
|
|||||||
|
virshaudit.py
|
55
actions/virshaudit.py
Executable file
55
actions/virshaudit.py
Executable file
@ -0,0 +1,55 @@
|
|||||||
|
#!/usr/bin/env python3
|
||||||
|
#
|
||||||
|
# Copyright 2020 Canonical Ltd
|
||||||
|
#
|
||||||
|
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
# you may not use this file except in compliance with the License.
|
||||||
|
# You may obtain a copy of the License at
|
||||||
|
#
|
||||||
|
# http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
#
|
||||||
|
# Unless required by applicable law or agreed to in writing, software
|
||||||
|
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
# See the License for the specific language governing permissions and
|
||||||
|
# limitations under the License.
|
||||||
|
|
||||||
|
import os
|
||||||
|
import sys
|
||||||
|
|
||||||
|
_path = os.path.dirname(os.path.realpath(__file__))
|
||||||
|
_hooks = os.path.abspath(os.path.join(_path, '../hooks'))
|
||||||
|
|
||||||
|
|
||||||
|
def _add_path(path):
|
||||||
|
if path not in sys.path:
|
||||||
|
sys.path.insert(1, path)
|
||||||
|
|
||||||
|
|
||||||
|
_add_path(_hooks)
|
||||||
|
|
||||||
|
|
||||||
|
import subprocess
|
||||||
|
from charmhelpers.core import hookenv
|
||||||
|
|
||||||
|
|
||||||
|
def virsh_audit():
|
||||||
|
"""
|
||||||
|
Return the list of VM instances as virsh sees on the
|
||||||
|
compute node
|
||||||
|
"""
|
||||||
|
outmap = {}
|
||||||
|
cmd = "virsh list --all"
|
||||||
|
try:
|
||||||
|
outmap['virsh-domains'] = subprocess.check_output(
|
||||||
|
cmd, shell=True).decode('UTF-8')
|
||||||
|
except subprocess.CalledProcessError as e:
|
||||||
|
hookenv.log(e)
|
||||||
|
hookenv.action_fail(
|
||||||
|
"Getting virsh list report failed: {}".format(e.message)
|
||||||
|
)
|
||||||
|
hookenv.action_set(outmap)
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == '__main__':
|
||||||
|
virsh_audit()
|
@ -50,6 +50,7 @@ tests:
|
|||||||
- zaza.openstack.charm_tests.nova.tests.LTSGuestCreateTest
|
- zaza.openstack.charm_tests.nova.tests.LTSGuestCreateTest
|
||||||
- zaza.openstack.charm_tests.nova.tests.CloudActions
|
- zaza.openstack.charm_tests.nova.tests.CloudActions
|
||||||
- zaza.openstack.charm_tests.nova.tests.NovaCompute
|
- zaza.openstack.charm_tests.nova.tests.NovaCompute
|
||||||
|
- zaza.openstack.charm_tests.nova.tests.NovaComputeActionTest
|
||||||
- zaza.openstack.charm_tests.nova.tests.SecurityTests
|
- zaza.openstack.charm_tests.nova.tests.SecurityTests
|
||||||
|
|
||||||
tests_options:
|
tests_options:
|
||||||
|
36
unit_tests/test_actions_virsh_audit.py
Normal file
36
unit_tests/test_actions_virsh_audit.py
Normal file
@ -0,0 +1,36 @@
|
|||||||
|
# Copyright 2020 Canonical Ltd
|
||||||
|
#
|
||||||
|
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
# you may not use this file except in compliance with the License.
|
||||||
|
# You may obtain a copy of the License at
|
||||||
|
#
|
||||||
|
# http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
#
|
||||||
|
# Unless required by applicable law or agreed to in writing, software
|
||||||
|
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
# See the License for the specific language governing permissions and
|
||||||
|
# limitations under the License.
|
||||||
|
|
||||||
|
import mock
|
||||||
|
from test_utils import CharmTestCase
|
||||||
|
import virshaudit as actions
|
||||||
|
|
||||||
|
|
||||||
|
class MainTestCase(CharmTestCase):
|
||||||
|
def setUp(self):
|
||||||
|
pass
|
||||||
|
|
||||||
|
@mock.patch('subprocess.check_output')
|
||||||
|
@mock.patch('charmhelpers.core.hookenv.action_set')
|
||||||
|
def test_virsh_audit(self, mock_action_set, mock_check_output):
|
||||||
|
virsh_output = "1 instance-00000001 running"
|
||||||
|
mock_check_output.return_value = virsh_output.encode()
|
||||||
|
dummy_action = []
|
||||||
|
mock_action_set.side_effect = dummy_action.append
|
||||||
|
actions.virsh_audit()
|
||||||
|
self.assertEqual(len(dummy_action), 1)
|
||||||
|
d = dummy_action[0]
|
||||||
|
self.assertIsInstance(d, dict)
|
||||||
|
self.assert_('virsh-domains' in d)
|
||||||
|
self.assertEqual(d['virsh-domains'], virsh_output)
|
Loading…
x
Reference in New Issue
Block a user