def delete(self, ns_name, wait=True): vnfs = self.get_field(ns_name, 'constituent-vnfr-ref') resp = self._terminate(ns_name) if 'success' not in resp: raise ClientException("failed to delete ns {}".format(ns_name)) # helper method to check if pkg exists def check_not_exists(func): try: func() return False except NotFound: return True for vnf in vnfs: if (not utils.wait_for_value( lambda: check_not_exists(lambda: self._client.vnf.get(vnf['vnfr-id'])))): raise ClientException( "vnf {} failed to delete".format(vnf['vnfr-id'])) if not utils.wait_for_value(lambda: check_not_exists(lambda: self.get(ns_name))): raise ClientException("ns {} failed to delete".format(ns_name))
def vnf_test(self,osm, openstack, vim, vmware, vnfd_file_list, nsd_file_list, ns_scale=False): # FIXME: need sleep after vim creation. Need a way to validate vim is ready to handle requests time.sleep(20) for file in nsd_file_list: nsd_desc = osm.get_api().package.get_key_val_from_pkg(file) ns_name=osm.ns_name_prefix+nsd_desc['name'] assert osm.get_api().ns.create(nsd_desc['name'],ns_name,vim.vim_name) # commenting the init check as sometime it is going to running state very fast # if not utils.wait_for_value(lambda: osm.get_api().ns.get_field(ns_name,'operational-status'),result='init', wait_time=30): # nsr=osm.get_api().ns.get(ns_name) # pprint.pprint(nsr) # assert True, "operational-status != init" # make sure ns is running if not utils.wait_for_value(lambda: osm.get_api().ns.get_field(ns_name,'operational-status'),result='running',wait_time=240): nsr=osm.get_api().ns.get(ns_name) pprint.pprint(nsr) assert True, "operational-status != running" if ns_scale: # for each descriptor, scale it for scale in nsd_desc['scaling-group-descriptor']: # scale it. assert not osm.get_api().ns.scale(ns_name, scale['name'], 1) # ensure ns is scaling-out assert utils.wait_for_value(lambda: osm.get_api().ns.get_field(ns_name,'operational-status'),result='scaling-out',wait_time=120) # wait for ns to be in running-state assert utils.wait_for_value(lambda: osm.get_api().ns.get_field(ns_name,'operational-status'),result='running',wait_time=300) time.sleep(10) assert not osm.get_api().ns.delete(ns_name, wait=True) #wait for the ns to delete #try: # utils.wait_for_value( lambda: osm.get_api().ns.get(ns_name), result=False, wait_time=180) #except: # print("Exception: Failed to get NAME after NS DELETE ... ") #TODO find the reason for 502 exception from osmclient/nbi try: assert not osm.get_api().nsd.delete(nsd_desc['name']) except: print("Exception: NSD Delete exception ...due to 502 error") time.sleep(10) for file in vnfd_file_list: vnfd_desc = osm.get_api().package.get_key_val_from_pkg(file) assert not osm.get_api().vnfd.delete(vnfd_desc['name'])
def test_wait_for_method_wait_for_change(self): def foobar(): if foobar.counter == 0: return True foobar.counter -= 1 return False foobar.counter = 1 assert utils.wait_for_value(lambda: foobar(), wait_time=1)
def test_wait_for_method_first_exception(self): def foobar(): if foobar.counter == 0: return True foobar.counter -= 1 raise Exception('send exception') foobar.counter = 1 assert utils.wait_for_value(lambda: foobar(), wait_time=1, catch_exception=Exception)
def _wait_for_package(self, pkg_type): if 'vnfd' in pkg_type['type']: get_method = self._client.vnfd.get elif 'nsd' in pkg_type['type']: get_method = self._client.nsd.get else: raise ClientException("no valid package type found") # helper method to check if pkg exists def check_exists(func): try: func() except NotFound: return False return True return utils.wait_for_value( lambda: check_exists(lambda: get_method(pkg_type['name'])))
def test_wait_for_method_exception(self): def foobar(): raise Exception('send exception') assert not utils.wait_for_value( lambda: foobar(), wait_time=0, catch_exception=Exception)
def test_wait_for_method_paramter(self): def foobar(input): return input assert not utils.wait_for_value(lambda: foobar(False), wait_time=0) assert utils.wait_for_value(lambda: foobar(True), wait_time=0)
def test_wait_for_method_timeout(self): def foobar(): return False assert not utils.wait_for_value(lambda: foobar(), wait_time=0)
def test_wait_for_method_basic(self): def foobar(): return True assert utils.wait_for_value(lambda: foobar())