def test_list_sfcs(self): with mock.patch.object(self.tacker_client, 'list_sfcs', return_value=self.sfclist): resp = openstack_tacker.list_sfcs(self.tacker_client, verbose=False) self.assertEqual(resp, ['test_sfc1', 'test_sfc2'])
def get_tacker_sfcs(tacker_client): logger.debug("Getting Tacker SFCs...") dic_sfcs = {} sfcs = os_tacker.list_sfcs(tacker_client, verbose=True)['sfcs'] if not (sfcs is None or len(sfcs) == 0): for sfc in sfcs: dic_sfcs.update({sfc['id']: sfc['name']}) return {'sfcs': dic_sfcs}
def delete_sfcs(): t = os_tacker.get_tacker_client() sfcs = os_tacker.list_sfcs(t) if sfcs is None: return for sfc in sfcs: logger.info("Removing sfc: {0}".format(sfc)) os_tacker.delete_sfc(t, sfc_id=sfc)
def test_list_sfcs_exception(self, mock_logger_error): with mock.patch.object(self.tacker_client, 'list_sfcs', side_effect=Exception): resp = openstack_tacker.list_sfcs(self.tacker_client, verbose=False) mock_logger_error.assert_called_once_with( test_utils.SubstrMatch("Error" " [list" "_sfcs(" "tacker_" "client)]:")) self.assertIsNone(resp)
def remove_tacker_sfcs(tacker_client, default_sfcs): logger.debug("Removing Tacker SFCs...") sfcs = os_tacker.list_sfcs(tacker_client, verbose=True)['sfcs'] if sfcs is None: logger.debug("There are no Tacker SFCs in the deployment. ") return for sfc in sfcs: sfc_name = sfc['name'] sfc_id = sfc['id'] logger.debug("'%s', ID=%s " % (sfc_name, sfc_id)) if (sfc_id not in default_sfcs and sfc_name not in default_sfcs.values()): logger.debug(" Removing '%s'..." % sfc_name) deleted = os_tacker.delete_sfc(tacker_client, sfc_id=sfc_id) if deleted is not None: logger.debug(" > Done!") else: logger.error("There has been a problem removing the " "SFC '%s'(%s)..." % (sfc_name, sfc_id)) else: logger.debug(" > this is a default SFC and will " "NOT be deleted.")