Skip to content
This repository has been archived by the owner on Oct 26, 2022. It is now read-only.

Commit

Permalink
changes to handle geni-api w.r.t ticketreview and comet cert validati…
Browse files Browse the repository at this point in the history
…on for enumerate
  • Loading branch information
kthare10 committed Aug 10, 2020
1 parent c75f7f0 commit d5fa060
Show file tree
Hide file tree
Showing 4 changed files with 124 additions and 34 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -807,7 +807,14 @@ public Map<String, Object> SliverStatus(String slice_urn, Object[] credentials,
if (r.getState() == OrcaConstants.ReservationStateFailed) {
en.put(ApiReturnFields.GENI_ERROR.name, (r.getNotices() != null ? r.getNotices()
: "ERROR: no detailed error message available"));
} else {
}
else if (r.getState() == OrcaConstants.ReservationStateClosed && r.getNotices() != null &&
r.getNotices().toLowerCase().contains("insufficient")) {
en.put(ApiReturnFields.GENI_ERROR.name, (r.getNotices() != null ? r.getNotices()
: "ERROR: no detailed error message available"));
en.put(ApiReturnFields.GENI_STATUS.name, GeniStates.FAILED.name);
}
else {
en.put(ApiReturnFields.GENI_ERROR.name, "");
}
// en.put(ApiReturnFields.ORCA_EXPIRES.name, (new Date(r.getEnd())).toString()); //ORCA reservation
Expand Down
12 changes: 3 additions & 9 deletions handlers/ec2/resources/scripts/comet_common_iface.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,10 +62,7 @@ def get_family(self, host, sliceId, rId, readToken, family):
'Key':rId,
'readToken':readToken
}
if self._verify == False:
response = requests.get((host + '/readScope'), headers=self._headers(), params=params, verify=False)
else:
response = requests.get((host + '/readScope'), headers=self._headers(), params=params, cert= self._cert, verify=False)
response = requests.get((host + '/readScope'), headers=self._headers(), params=params, verify=False)
self._log.debug ("get_family: Received Response Status Code: " + str(response.status_code))
if response.status_code == 200 :
self._log.debug ("get_family: Received Response Message: " + response.json()["message"])
Expand Down Expand Up @@ -105,7 +102,7 @@ def delete_family(self, host, sliceId, rId, readToken, writeToken, family):
if self._verify == False:
response = requests.delete((host +'/deleteScope'), headers=self._headers(), params=params, verify=False)
else:
response = requests.delete((host +'/deleteScope'), headers=self._headers(), params=params, cert= self._cert, verify=False)
response = requests.delete((host +'/deleteScope'), headers=self._headers(), params=params, cert= self._cert, verify=self._verify)
self._log.debug ("delete_family: Received Response Status Code: " + str(response.status_code))
if response.status_code == 200 :
self._log.debug ("delete_family: Received Response Message: " + response.json()["message"])
Expand All @@ -128,10 +125,7 @@ def enumerate_families(self, host, sliceId, readToken, family=None):
'family':family,
}

if self._verify == False:
response = requests.get((host +'/enumerateScope'), headers=self._headers(), params=params, verify=False)
else:
response = requests.get((host +'/enumerateScope'), headers=self._headers(), params=params, cert= self._cert, verify=False)
response = requests.get((host +'/enumerateScope'), headers=self._headers(), params=params, verify=False)
self._log.debug ("enumerate_families: Received Response Status Code: " + str(response.status_code))
if response.status_code == 200 :
self._log.debug ("enumerate_families: Received Response Message: " + response.json()["message"])
Expand Down
56 changes: 50 additions & 6 deletions handlers/ec2/resources/scripts/nova_essex_common.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
import signal
import time
import traceback
import stat
import tempfile
from os import kill
from signal import alarm, signal, SIGALRM, SIGKILL
from subprocess import *
Expand Down Expand Up @@ -290,6 +292,53 @@ def create_project(self, project_name):

return new_project_id

@classmethod
def atomic_output(self, file_contents, output_fname):
"""
Take a Python object and attempt to serialize it to JSON and write
the resulting bytes to an output file atomically.
This function does not return a value and throws an exception on failure.
:param output_object: A Python object to be serialized into JSON.
:param output_fname: A filename to write the object into.
:type output_fname: string
"""

dir_name, file_name = os.path.split(output_fname)

tmp_fd, tmp_file_name = tempfile.mkstemp(dir = dir_name, prefix=file_name)
try:
with os.fdopen(tmp_fd, 'w') as fp:
fp.write(file_contents)

# atomically move new tokens in place
self.atomic_rename(tmp_file_name, output_fname)

finally:
try:
os.unlink(tmp_file_name)
except OSError:
pass


@classmethod
def atomic_rename(self, tmp_file, target_file, mode=stat.S_IRUSR):
"""
If successful Credmgr will only be dealing with fully prepared and
usable credential cache files.
:param tmp_file: The temp file path containing
the TGT acquired from the ngbauth service.
:type tmp_file: string
:param target_file: The target file.
:return: Whether the chmod/rename was successful.
:rtype: bool
"""

os.chmod(tmp_file, mode)
os.rename(tmp_file, target_file)


@classmethod
def generate_user_keystone_file(self, project_name, user_name, user_pwd, ec2_auth_url):
Expand Down Expand Up @@ -569,13 +618,8 @@ def generate_key_file(self, user_name, ssh_key):
time.sleep(4)
return key_file

fd = None
try:
fd = open(key_file, 'a+')
fd.seek(0)
fd.truncate()
fd.write(ssh_key)
fd.close
self.atomic_output(ssh_key, key_file)
except Exception as e:
LOG.error("Exception occured e=" + str(e))
raise Openstack_Command_Fail('failed to write to key file ' + key_file)
Expand Down
81 changes: 63 additions & 18 deletions handlers/providers/resources/scripts/nova_essex_common.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
import signal
import time
import traceback
import stat
import tempfile
from os import kill
from signal import alarm, signal, SIGALRM, SIGKILL
from subprocess import *
Expand Down Expand Up @@ -290,6 +292,53 @@ def create_project(self, project_name):

return new_project_id

@classmethod
def atomic_output(self, file_contents, output_fname):
"""
Take a Python object and attempt to serialize it to JSON and write
the resulting bytes to an output file atomically.
This function does not return a value and throws an exception on failure.
:param output_object: A Python object to be serialized into JSON.
:param output_fname: A filename to write the object into.
:type output_fname: string
"""

dir_name, file_name = os.path.split(output_fname)

tmp_fd, tmp_file_name = tempfile.mkstemp(dir = dir_name, prefix=file_name)
try:
with os.fdopen(tmp_fd, 'w') as fp:
fp.write(file_contents)

# atomically move new tokens in place
self.atomic_rename(tmp_file_name, output_fname)

finally:
try:
os.unlink(tmp_file_name)
except OSError:
pass


@classmethod
def atomic_rename(self, tmp_file, target_file, mode=stat.S_IRUSR):
"""
If successful Credmgr will only be dealing with fully prepared and
usable credential cache files.
:param tmp_file: The temp file path containing
the TGT acquired from the ngbauth service.
:type tmp_file: string
:param target_file: The target file.
:return: Whether the chmod/rename was successful.
:rtype: bool
"""

os.chmod(tmp_file, mode)
os.rename(tmp_file, target_file)


@classmethod
def generate_user_keystone_file(self, project_name, user_name, user_pwd, ec2_auth_url):
Expand Down Expand Up @@ -569,13 +618,8 @@ def generate_key_file(self, user_name, ssh_key):
time.sleep(4)
return key_file

fd = None
try:
fd = open(key_file, 'a+')
fd.seek(0)
fd.truncate()
fd.write(ssh_key)
fd.close
self.atomic_output(ssh_key, key_file)
except Exception as e:
LOG.error("Exception occured e=" + str(e))
raise Openstack_Command_Fail('failed to write to key file ' + key_file)
Expand Down Expand Up @@ -783,20 +827,21 @@ def _has_resources(self, project_name):

@classmethod
def _has_resources_poll(self, project_name, timeout):
retry = 3

begin = time.time()
while True:
time_passed = time.time() - begin
res = self._has_resources(project_name)

if res == False:
LOG.warning("openstack project " + str(project_name) + " has no resources")
return False
res = True
for i in range(retry):
begin = time.time()
while True:
time_passed = time.time() - begin
res = self._has_resources(project_name)

if time_passed > timeout:
break
time.sleep(10)
return True
if time_passed > timeout:
break
time.sleep(10)
if res == False:
LOG.warning("openstack project " + str(project_name) + " has no resources")
return res

@classmethod
def cleanup(self, project_name, user_name):
Expand Down

0 comments on commit d5fa060

Please sign in to comment.