Browse Source

Fix getting capacity in k8s_monitor

Remove parsing literal for capacity. K8s client returns an object
now.

Change-Id: I26b3e529ee69ea9e48e0bedfbf95dd77d2b78593
Depends-On: Ia55d01a7cfd6e11448272e5859dd84e40147b618
Closes-Bug: #1595373
changes/10/423710/3
Spyros Trigazis 5 years ago
parent
commit
52be59345b
  1. 2
      magnum/drivers/common/k8s_monitor.py
  2. 2
      magnum/tests/unit/conductor/test_monitors.py

2
magnum/drivers/common/k8s_monitor.py

@ -158,7 +158,7 @@ class K8sMonitor(monitors.MonitorBase):
# Output of node.status.capacity is strong
# for example:
# capacity = "{'cpu': '1', 'memory': '1000Ki'}"
capacity = ast.literal_eval(node.status.capacity)
capacity = node.status.capacity
memory = utils.get_k8s_quantity(capacity['memory'])
cpu = int(capacity['cpu'])
parsed_nodes.append({'Memory': memory, 'Cpu': cpu})

2
magnum/tests/unit/conductor/test_monitors.py

@ -135,7 +135,7 @@ class MonitorsTestCase(base.TestCase):
mock_nodes = mock.MagicMock()
mock_node = mock.MagicMock()
mock_node.status = mock.MagicMock()
mock_node.status.capacity = "{'memory': '2000Ki', 'cpu': '1'}"
mock_node.status.capacity = {'memory': '2000Ki', 'cpu': '1'}
mock_nodes.items = [mock_node]
mock_k8s_api.return_value.list_namespaced_node.return_value = (
mock_nodes)

Loading…
Cancel
Save