implement zvm inspector init method
In zvm inspector init method, initialize cache, instance list and zhcp info. Change-Id: I7432490ff48378cf60f44ba6920901b246a54d3d
This commit is contained in:
parent
907ecc0a53
commit
aec0a62d3b
|
@ -16,6 +16,9 @@
|
|||
from ceilometer.compute.virt import inspector as virt_inspector
|
||||
from oslo_config import cfg
|
||||
from oslo_log import log
|
||||
from oslo_utils import timeutils
|
||||
|
||||
from ceilometer_zvm.compute.virt.zvm import utils as zvmutils
|
||||
|
||||
|
||||
zvm_ops = [
|
||||
|
@ -32,6 +35,9 @@ zvm_ops = [
|
|||
cfg.IntOpt('zvm_xcat_connection_timeout',
|
||||
default=600,
|
||||
help="The number of seconds wait for xCAT MN response"),
|
||||
cfg.StrOpt('xcat_zhcp_nodename',
|
||||
default='zhcp',
|
||||
help='xCat zHCP nodename in xCAT '),
|
||||
]
|
||||
|
||||
|
||||
|
@ -44,7 +50,16 @@ LOG = log.getLogger(__name__)
|
|||
class ZVMInspector(virt_inspector.Inspector):
|
||||
|
||||
def __init__(self):
|
||||
pass
|
||||
self.cache = zvmutils.CacheData()
|
||||
self.cache_expiration = timeutils.utcnow_ts()
|
||||
|
||||
self.instances = {}
|
||||
self.zhcp_info = {
|
||||
'nodename': CONF.zvm.xcat_zhcp_nodename,
|
||||
'hostname': zvmutils.get_node_hostname(
|
||||
CONF.zvm.xcat_zhcp_nodename),
|
||||
'userid': zvmutils.get_userid(CONF.zvm.xcat_zhcp_nodename)
|
||||
}
|
||||
|
||||
def inspect_cpus(self, instance):
|
||||
pass
|
||||
|
|
|
@ -307,3 +307,10 @@ def xdsh(node, commands):
|
|||
res_dict = xdsh_execute(node, commands)
|
||||
|
||||
return res_dict
|
||||
|
||||
|
||||
def get_node_hostname(node_name):
|
||||
addp = '&col=node&value=%s&attribute=hostnames' % node_name
|
||||
url = XCATUrl().gettab("/hosts", addp)
|
||||
with expect_invalid_xcat_resp_data():
|
||||
return xcat_request("GET", url)['data'][0][0]
|
||||
|
|
|
@ -13,16 +13,30 @@
|
|||
# under the License.
|
||||
|
||||
|
||||
import mock
|
||||
|
||||
from oslo_config import fixture as fixture_config
|
||||
from oslotest import base
|
||||
|
||||
from ceilometer_zvm.compute.virt.zvm import inspector as zvm_inspector
|
||||
from ceilometer_zvm.compute.virt.zvm import utils as zvmutils
|
||||
|
||||
|
||||
class TestZVMInspector(base.BaseTestCase):
|
||||
|
||||
def setUp(self):
|
||||
self.CONF = self.useFixture(
|
||||
fixture_config.Config(zvm_inspector.CONF)).conf
|
||||
self.CONF.set_override('xcat_zhcp_nodename', 'zhcp', 'zvm')
|
||||
super(TestZVMInspector, self).setUp()
|
||||
self.inspector = zvm_inspector.ZVMInspector()
|
||||
|
||||
get_nhn = mock.MagicMock(return_value='zhcp.com')
|
||||
get_uid = mock.MagicMock(return_value='zhcp')
|
||||
with mock.patch.multiple(zvmutils, get_node_hostname=get_nhn,
|
||||
get_userid=get_uid):
|
||||
self.inspector = zvm_inspector.ZVMInspector()
|
||||
|
||||
def test_init(self):
|
||||
self.assertIsInstance(self.inspector, zvm_inspector.ZVMInspector)
|
||||
self.assertEqual('zhcp', self.inspector.zhcp_info['nodename'])
|
||||
self.assertEqual('zhcp.com', self.inspector.zhcp_info['hostname'])
|
||||
self.assertEqual('zhcp', self.inspector.zhcp_info['userid'])
|
||||
|
|
|
@ -19,14 +19,15 @@ from oslo_config import fixture as fixture_config
|
|||
from oslo_serialization import jsonutils
|
||||
from oslotest import base
|
||||
|
||||
from ceilometer_zvm.compute.virt.zvm import inspector
|
||||
from ceilometer_zvm.compute.virt.zvm import inspector as zvm_inspector
|
||||
from ceilometer_zvm.compute.virt.zvm import utils as zvmutils
|
||||
|
||||
|
||||
class TestXCATUrl(base.BaseTestCase):
|
||||
|
||||
def setUp(self):
|
||||
self.CONF = self.useFixture(fixture_config.Config(inspector.CONF)).conf
|
||||
self.CONF = self.useFixture(
|
||||
fixture_config.Config(zvm_inspector.CONF)).conf
|
||||
self.CONF.set_override('zvm_xcat_username', 'user', 'zvm')
|
||||
self.CONF.set_override('zvm_xcat_password', 'pwd', 'zvm')
|
||||
super(TestXCATUrl, self).setUp()
|
||||
|
@ -56,7 +57,8 @@ class TestXCATUrl(base.BaseTestCase):
|
|||
class TestXCATConnection(base.BaseTestCase):
|
||||
|
||||
def setUp(self):
|
||||
self.CONF = self.useFixture(fixture_config.Config(inspector.CONF)).conf
|
||||
self.CONF = self.useFixture(
|
||||
fixture_config.Config(zvm_inspector.CONF)).conf
|
||||
self.CONF.set_override('zvm_xcat_server', '1.1.1.1', 'zvm')
|
||||
self.CONF.set_override('zvm_xcat_username', 'user', 'zvm')
|
||||
self.CONF.set_override('zvm_xcat_password', 'pwd', 'zvm')
|
||||
|
@ -92,7 +94,8 @@ class TestXCATConnection(base.BaseTestCase):
|
|||
class TestZVMUtils(base.BaseTestCase):
|
||||
|
||||
def setUp(self):
|
||||
self.CONF = self.useFixture(fixture_config.Config(inspector.CONF)).conf
|
||||
self.CONF = self.useFixture(
|
||||
fixture_config.Config(zvm_inspector.CONF)).conf
|
||||
self.CONF.set_override('zvm_xcat_server', '1.1.1.1', 'zvm')
|
||||
self.CONF.set_override('zvm_xcat_username', 'user', 'zvm')
|
||||
self.CONF.set_override('zvm_xcat_password', 'pwd', 'zvm')
|
||||
|
@ -117,6 +120,11 @@ class TestZVMUtils(base.BaseTestCase):
|
|||
'/xcatws/nodes/node/dsh?userName=user&password=pwd&format=json',
|
||||
['command=cmds'])
|
||||
|
||||
@mock.patch('ceilometer_zvm.compute.virt.zvm.utils.xcat_request')
|
||||
def test_get_node_hostname(self, xcat_req):
|
||||
xcat_req.return_value = {'data': [['hostname']]}
|
||||
self.assertEqual('hostname', zvmutils.get_node_hostname('nodename'))
|
||||
|
||||
|
||||
class TestCacheData(base.BaseTestCase):
|
||||
|
||||
|
|
Loading…
Reference in New Issue