Skip to content

Commit

Permalink
Fixed crumbs issue : Add Network Fails in Webapp After Period of Ina…
Browse files Browse the repository at this point in the history
…ctivity Juniper#43

      added ARM64 support. By some reason PyYAML 5.4 could not be built on ARM64 based ubuntu.
      Probably this issue: yaml/pyyaml#724.
  • Loading branch information
vpomuran committed Oct 17, 2024
1 parent 4b08b05 commit 1cfbc4b
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 7 deletions.
40 changes: 33 additions & 7 deletions build-and-test-webapp/nita-webapp/ngcn_workbench/ngcn/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -534,7 +534,7 @@ def deleteCampusTypeView(request):

@login_required(login_url='/admin/login/')
def addCampusNetworkView(request):

global server
if request.method == 'POST':
form = CampusNetworkForm(data=request.POST, files=request.FILES)
if form.is_valid():
Expand Down Expand Up @@ -602,8 +602,16 @@ def addCampusNetworkView(request):
logger.info("resources for Campus Type: " + campusNetwork.campus_type.name + "::::: is Empty ")

#server.build_job(action_url,{'operation':'create', 'src':src, 'network_name':network_name, 'hosts':campusNetwork.host_file, 'project_yaml':yaml.safe_dump(project_yaml, default_flow_style=False)})
server.build_job(action_url,{'operation':'create', 'src':src, 'network_name':network_name, 'hosts':campusNetwork.host_file, 'network_desc':network_desc})

try:
server.build_job(action_url,{'operation':'create', 'src':src, 'network_name':network_name, 'hosts':campusNetwork.host_file, 'network_desc':network_desc})
except jenkins.JenkinsException as e:
msg=str(e)
if 'Forbidden' in msg: # most probably crumbs issue
# reauthenticate and try once more

server = jenkins.Jenkins(JENKINS_SERVER_URL, username=JENKINS_SERVER_USER, password=JENKINS_SERVER_PASS)
server.build_job(action_url,{'operation':'create', 'src':src, 'network_name':network_name, 'hosts':campusNetwork.host_file, 'network_desc':network_desc})

if wait_and_get_build_status(action_url,current_build_number) :
logger.info("Campus Network - " + campusNetwork.name + " creation network_template_manager job finished successfully")
campusNetwork.save()
Expand All @@ -627,7 +635,7 @@ def addCampusNetworkView(request):

@login_required(login_url='/admin/login/')
def editCampusNetworkView(request, campus_network_id):

global server
if request.method == 'POST':
campusNetwork = CampusNetwork.objects.get(pk=campus_network_id)
POST = request.POST.copy()
Expand All @@ -645,7 +653,15 @@ def editCampusNetworkView(request, campus_network_id):
network_name=data['name'].strip()
action_url = 'network_template_mgr';
current_build_number = server.get_job_info(action_url)['nextBuildNumber']
server.build_job(action_url,{'src':src,'network_name':network_name,'hosts':hostData,'operation':'update'})
try:
server.build_job(action_url,{'src':src,'network_name':network_name,'hosts':hostData,'operation':'update'})
except jenkins.JenkinsException as e:
msg=str(e)
if 'Forbidden' in msg: # most probably crumbs issue
# reauthenticate and try once more

server = jenkins.Jenkins(JENKINS_SERVER_URL, username=JENKINS_SERVER_USER, password=JENKINS_SERVER_PASS)
server.build_job(action_url,{'src':src,'network_name':network_name,'hosts':hostData,'operation':'update'})

if wait_and_get_build_status(action_url,current_build_number) :
campusNetwork.status = "Hosts file modified"
Expand All @@ -670,16 +686,26 @@ def editCampusNetworkView(request, campus_network_id):

@login_required(login_url='/admin/login/')
def deleteCampusNetworkView(request):
global server
if request.method == 'POST':
campus_network_ids=request.POST.get('campus_network_ids')

campusNetwork = CampusNetwork.objects.get(pk=campus_network_ids)
network_name=campusNetwork.name
src=ServerProperties.getWorkspaceLocation()+"/"+campusNetwork.campus_type.app_zip_name

action_url = 'network_template_mgr';
action_url = 'network_template_mgr'
current_build_number = server.get_job_info(action_url)['nextBuildNumber']
server.build_job(action_url,{'src':src,'network_name':network_name,'operation':'delete'})
try:
server.build_job(action_url,{'src':src,'network_name':network_name,'operation':'delete'})
except jenkins.JenkinsException as e:
msg=str(e)
if 'Forbidden' in msg: # most probably crumbs issue
# reauthenticate and try once more

server = jenkins.Jenkins(JENKINS_SERVER_URL, username=JENKINS_SERVER_USER, password=JENKINS_SERVER_PASS)
server.build_job(action_url,{'src':src,'network_name':network_name,'operation':'delete'})

if wait_and_get_build_status(action_url,current_build_number) :
campusNetwork.delete()
return JsonResponse({'status':'success', 'name':network_name})
Expand Down
13 changes: 13 additions & 0 deletions build_container.sh
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,18 @@
# ********************************************************

set -e
ARCH=`uname -p`
if [ $ARCH = aarch64 ] ; then # it is ARM64
# By some reason PyYAML does not work with 5.4 version so change it to 5.3
REQ_WEBAPP_BACKUP=/var/tmp/requirements.txt.$$
cp requirements.txt ${REQ_WEBAPP_BACKUP}
cat requirements.txt | sed 's/PyYAML==5.4/PyYAML==5.3/' > /var/tmp/requirements.tmp.$$
mv /var/tmp/requirements.tmp.$$ requirements.txt
fi

docker build -t juniper/nita-webapp:22.8-1 .

if [ $ARCH = aarch64 ] ; then
# By some reason PyYAML does not work with 5.4 version so change it to 5.3
mv ${REQ_WEBAPP_BACKUP} requirements.txt
fi

0 comments on commit 1cfbc4b

Please sign in to comment.