Skip to content
Snippets Groups Projects
Commit 3b80eb2c authored by Iustin Pop's avatar Iustin Pop
Browse files

hv_fake: remove hard-coded path constructs


This changes to hv_fake to PathJoin.

Signed-off-by: default avatarIustin Pop <iustin@google.com>
Reviewed-by: default avatarMichael Hanselmann <hansmi@google.com>
parent 6b0391b3
No related branches found
No related tags found
No related merge requests found
...@@ -61,7 +61,7 @@ class FakeHypervisor(hv_base.BaseHypervisor): ...@@ -61,7 +61,7 @@ class FakeHypervisor(hv_base.BaseHypervisor):
@return: tuple of (name, id, memory, vcpus, stat, times) @return: tuple of (name, id, memory, vcpus, stat, times)
""" """
file_name = "%s/%s" % (self._ROOT_DIR, instance_name) file_name = self._InstanceFile(instance_name)
if not os.path.exists(file_name): if not os.path.exists(file_name):
return None return None
try: try:
...@@ -88,7 +88,7 @@ class FakeHypervisor(hv_base.BaseHypervisor): ...@@ -88,7 +88,7 @@ class FakeHypervisor(hv_base.BaseHypervisor):
data = [] data = []
for file_name in os.listdir(self._ROOT_DIR): for file_name in os.listdir(self._ROOT_DIR):
try: try:
fh = open(self._ROOT_DIR + "/" + file_name, "r") fh = open(utils.PathJoin(self._ROOT_DIR, file_name), "r")
inst_id = "-1" inst_id = "-1"
memory = 0 memory = 0
vcpus = 1 vcpus = 1
...@@ -107,12 +107,12 @@ class FakeHypervisor(hv_base.BaseHypervisor): ...@@ -107,12 +107,12 @@ class FakeHypervisor(hv_base.BaseHypervisor):
raise errors.HypervisorError("Failed to list instances: %s" % err) raise errors.HypervisorError("Failed to list instances: %s" % err)
return data return data
@classmethod
def _InstanceFile(self, instance_name): def _InstanceFile(cls, instance_name):
"""Compute the instance file for an instance name. """Compute the instance file for an instance name.
""" """
return self._ROOT_DIR + "/%s" % instance_name return utils.PathJoin(cls._ROOT_DIR, instance_name)
def _IsAlive(self, instance_name): def _IsAlive(self, instance_name):
"""Checks if an instance is alive. """Checks if an instance is alive.
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment