DeployHubProject / DeployHub-Pro

DeployHub Pro Pipeline Status Project
https://www.openmakesoftware.com/application-release-automation-for-continuous-delivery/
Other
11 stars 4 forks source link

try/catch displays error output #233

Open sbtaylor15 opened 6 years ago

sbtaylor15 commented 6 years ago

Try/Catch of invalid parse from restful_get shows output in red in log. try catch should now display output by default

pgibbs-openmake commented 6 years ago

Can you paste the DMScript in here so I can see what it looks like? I presume:

try { set res = restful_get(...); } catch(ex) { echo $ex; }

Are you saying the parse error is being reported to stderr (in red) at the set res = part or the echo in the catch block (if any) is reporting to stderr?

sbtaylor15 commented 6 years ago

set servers = ${environment.servers}; set cookiejar = "";

iterate(s: $servers) { if (${s.name.lower().substr(0,3)} = "rs_") { set attrs = ${s.attributes}; set OpenStackUser = $attrs['OpenStackUser']; set OpenStackApiKey = $attrs['OpenStackApiKey']; set OpenStackIdentity = $attrs['OpenStackIdentity']; set OpenStackEndPoint = $attrs['OpenStackEndPoint']; set OpenStackTenantID = $attrs['OpenStackTenantID']; set OpenStackImage = $attrs['OpenStackImage']; set OpenStackFlavor = $attrs['OpenStackFlavor']; set OpenStackKeyName = $attrs['OpenStackKeyName'];

set login = {"auth":{"RAX-KSKEY:apiKeyCredentials":{"username":"$OpenStackUser","apiKey":"$OpenStackApiKey"}}}; set res = restful_post("$OpenStackIdentity",$login); set token = ${res.access.token.id};

set auth={"X-Auth-Token": "$token"}; // Returned token will be included in the header set res = restful_get("https://$OpenStackEndPoint/v2/$OpenStackTenantID/servers",null,null,$auth);

set found = 0; set instanceid = ""; set x = length(${res.servers});

for (n = 0; $n < $x; n = $n + 1) { set server = $res["servers"][$n]; set name = ${server.name}; set instanceid = ${server.id};

if ($name = ${s.hostname})
{
 set found = 1;
}

}

if ($found = 1) { echo "${s.hostname} is up and running on $instanceid"; } else { set serverdef = {"server": {"name": "${s.hostname}", "imageRef": "$OpenStackImage", "flavorRef": "$OpenStackFlavor", "key_name":"$OpenStackKeyName"}}; set res = restful_post("https://$OpenStackEndPoint/v2/$OpenStackTenantID/servers",$serverdef,null,$auth); set serverid = ${res.server.id}; echo $serverid;

set foundip=0;
set myip = "";

while ($foundip = 0)
{
 try
 {
  set res = restful_get("https://$OpenStackEndPoint/v2/$OpenStackTenantID/servers/$serverid",null,null,$auth);
  set iplist = ${res.server.addresses.public};
  set x = length($iplist);

  for (n = 0; $n < $x; n = $n + 1)
  {
   if ($iplist[$n]['version'] = 4)
   {
    set foundip = 1;
    set myip = $iplist[$n]['addr'];
   }
  }
 }
 catch (ex)
 {
                 echo "Sleeping";
  sleep(delay: 30);
 }
}

echo "Setting ${s.hostname} to $myip";
set res = restful_get("https://members.dyndns.org/v3/update?hostname=${s.hostname}&myip=$myip","","","dyndns");
echo $res;
echo "";
echo "server is ${s.name}";
echo "hostname is ${s.hostname}";
set ready = DNSReady(${s.hostname},$myip);
echo $ready;

} } else { if (${s.name.lower().substr(0,3)} != "zos") { set parms = ["ec2", "describe-instances", "--filters", "Name=instance-state-name,Values=running"];

set myvar = AwsEC2($parms); set found = 0; set instanceid = ""; set x = length(${myvar.Reservations});

for (n = 0; $n < $x; n = $n + 1) { set res = $myvar["Reservations"][$n]; set name = ${res.Instances[0].Tags[0].Value}; set instanceid = ${res.Instances[0].InstanceId};

 if ($name = ${s.hostname})
 {
  set found = 1;
 }

}

if ($found = 1) { echo "${s.hostname} is up and running on $instanceid"; } else { set parms = ["ec2", "run-instances", "--image-id", $ImageId, "--count", "1", "--instance-type", $InstanceType, "--key-name", $KeyName, "--security-group-ids", $SecurityGroupIds, "--subnet-id", $SubNetId, "--associate-public-ip-address", "--tag-specifications", "ResourceType=instance,Tags=[{Key=Name,Value=${s.hostname}}]"];

set myvar = AwsEC2($parms);
set instanceid = ${myvar.Instances[0].InstanceId};
echo "INSTANCE ID=$instanceid";

set parms = ["ec2", "describe-instances", "--instance-ids", $instanceid];
set myvar = AwsEC2($parms);

set myip = ${myvar.Reservations[0].Instances[0].PublicIpAddress};
echo "Setting ${s.hostname} to $myip";
set res = restful_get("https://members.dyndns.org/v3/update?hostname=${s.hostname}&myip=$myip","","","dyndns");
echo $res;
echo "";
echo "server is ${s.name}";
echo "hostname is ${s.hostname}";
set ready = DNSReady(${s.hostname},$myip);
echo $ready;

} } } }

sbtaylor15 commented 6 years ago

INFO: Starting deployment #1780

INFO: Deploying Application "IT Guys;3" into Environment "IT Guys Dev ZS" INFO: Rolling Forward from NULL to IT Guys;3 {"server":{"imageRef":"59ab613b-8040-4a06-a5de-61a8a337b2c6","key_name":"steve","flavorRef":2,"name":"zs-itguys-dev.gotdns.com"}} 6f44aa9d-69a2-4874-b695-f088b2c3c700 Syntax error at line 1: {"server": {"status": "BUILD", "updated": "2017-12-07T22:52:53Z", "hostId": "", "addresses": {>>>}<<<, "links": [{"href": "https://dfw.servers.api.rackspacecloud.com/v2/1025100/servers/6f44aa9d-69a2-4874-b695-f088b2c3c700", "rel": "self"}, {"href": "https://dfw.servers.api.rackspacecloud.com/1025100/servers/6f44aa9d-69a2-4874-b695-f088b2c3c700", "rel": "bookmark"}], "key_name": "steve", "image": {"id": "59ab613b-8040-4a06-a5de-61a8a337b2c6", "links": [{"href": "https://dfw.servers.api.rackspacecloud.com/1025100/images/59ab613b-8040-4a06-a5de-61a8a337b2c6", "rel": "bookmark"}]}, "RAX-PUBLIC-IP-ZONE-ID:publicIPZoneId": "118df98ffba182a9ca16b796c24dc45e95d60122645d82eb0d9c387f", "OS-EXT-STS:task_state": "scheduling", "OS-EXT-STS:vm_state": "building", "flavor": {"id": "2", "links": [{"href": "https://dfw.servers.api.rackspacecloud.com/1025100/flavors/2", "rel": "bookmark"}]}, "id": "6f44aa9d-69a2-4874-b695-f088b2c3c700", "user_id": "a1f874751044405396a148b2787b8fc3", "name": "zs-itguys-dev.gotdns.com", "created": "2017-12-07T22:52:52Z", "tenant_id": "1025100", "OS-DCF:diskConfig": "MANUAL", "accessIPv4": "", "accessIPv6": "", "progress": 0, "OS-EXT-STS:power_state": 0, "config_drive": "", "metadata": {}}}syntax error, unexpected '}', expecting string literal Sleeping Syntax error at line 1: {"server": {"status": "BUILD", "updated": "2017-12-07T22:52:55Z", "hostId": "67dabd3c2cfdda50f92d62b056cfaaa2947bcfc31e651842bcb92728", "addresses": {"public": [{"version": 4, "addr": "192.237.214.196"}, {"version": 6, "addr": "2001:4800:7813:516:be76:4eff:fe04:d236"}], "private": [{"version": 4, "addr": "10.183.4.230"}]}, "links": [{"href": "https://dfw.servers.api.rackspacecloud.com/v2/1025100/servers/6f44aa9d-69a2-4874-b695-f088b2c3c700", "rel": "self"}, {"href": "https://dfw.servers.api.rackspacecloud.com/1025100/servers/6f44aa9d-69a2-4874-b695-f088b2c3c700", "rel": "bookmark"}], "key_name": "steve", "image": {"id": "59ab613b-8040-4a06-a5de-61a8a337b2c6", "links": [{"href": "https://dfw.servers.api.rackspacecloud.com/1025100/images/59ab613b-8040-4a06-a5de-61a8a337b2c6", "rel": "bookmark"}]}, "RAX-PUBLIC-IP-ZONE-ID:publicIPZoneId": "118df98ffba182a9ca16b796c24dc45e95d60122645d82eb0d9c387f", "OS-EXT-STS:task_state": "spawning", "OS-EXT-STS:vm_state": "building", "flavor": {"id": "2", "links": [{"href": "https://dfw.servers.api.rackspacecloud.com/1025100/flavors/2", "rel": "bookmark"}]}, "id": "6f44aa9d-69a2-4874-b695-f088b2c3c700", "user_id": "a1f874751044405396a148b2787b8fc3", "name": "zs-itguys-dev.gotdns.com", "created": "2017-12-07T22:52:52Z", "tenant_id": "1025100", "OS-DCF:diskConfig": "MANUAL", "accessIPv4": "", "accessIPv6": "", "progress": 10, "OS-EXT-STS:power_state": 0, "config_drive": "", "metadata": {>>>}<<<}}syntax error, unexpected '}', expecting string literal Sleeping Syntax error at line 1: {"server": {"status": "BUILD", "updated": "2017-12-07T22:52:55Z", "hostId": "67dabd3c2cfdda50f92d62b056cfaaa2947bcfc31e651842bcb92728", "addresses": {"public": [{"version": 4, "addr": "192.237.214.196"}, {"version": 6, "addr": "2001:4800:7813:516:be76:4eff:fe04:d236"}], "private": [{"version": 4, "addr": "10.183.4.230"}]}, "links": [{"href": "https://dfw.servers.api.rackspacecloud.com/v2/1025100/servers/6f44aa9d-69a2-4874-b695-f088b2c3c700", "rel": "self"}, {"href": "https://dfw.servers.api.rackspacecloud.com/1025100/servers/6f44aa9d-69a2-4874-b695-f088b2c3c700", "rel": "bookmark"}], "key_name": "steve", "image": {"id": "59ab613b-8040-4a06-a5de-61a8a337b2c6", "links": [{"href": "https://dfw.servers.api.rackspacecloud.com/1025100/images/59ab613b-8040-4a06-a5de-61a8a337b2c6", "rel": "bookmark"}]}, "RAX-PUBLIC-IP-ZONE-ID:publicIPZoneId": "118df98ffba182a9ca16b796c24dc45e95d60122645d82eb0d9c387f", "OS-EXT-STS:task_state": "spawning", "OS-EXT-STS:vm_state": "building", "flavor": {"id": "2", "links": [{"href": "https://dfw.servers.api.rackspacecloud.com/1025100/flavors/2", "rel": "bookmark"}]}, "id": "6f44aa9d-69a2-4874-b695-f088b2c3c700", "user_id": "a1f874751044405396a148b2787b8fc3", "name": "zs-itguys-dev.gotdns.com", "created": "2017-12-07T22:52:52Z", "tenant_id": "1025100", "OS-DCF:diskConfig": "MANUAL", "accessIPv4": "", "accessIPv6": "", "progress": 10, "OS-EXT-STS:power_state": 0, "config_drive": "", "metadata": {>>>}<<<}}syntax error, unexpected '}', expecting string literal Sleeping Syntax error at line 1: {"server": {"status": "BUILD", "updated": "2017-12-07T22:52:55Z", "hostId": "67dabd3c2cfdda50f92d62b056cfaaa2947bcfc31e651842bcb92728", "addresses": {"public": [{"version": 4, "addr": "192.237.214.196"}, {"version": 6, "addr": "2001:4800:7813:516:be76:4eff:fe04:d236"}], "private": [{"version": 4, "addr": "10.183.4.230"}]}, "links": [{"href": "https://dfw.servers.api.rackspacecloud.com/v2/1025100/servers/6f44aa9d-69a2-4874-b695-f088b2c3c700", "rel": "self"}, {"href": "https://dfw.servers.api.rackspacecloud.com/1025100/servers/6f44aa9d-69a2-4874-b695-f088b2c3c700", "rel": "bookmark"}], "key_name": "steve", "image": {"id": "59ab613b-8040-4a06-a5de-61a8a337b2c6", "links": [{"href": "https://dfw.servers.api.rackspacecloud.com/1025100/images/59ab613b-8040-4a06-a5de-61a8a337b2c6", "rel": "bookmark"}]}, "RAX-PUBLIC-IP-ZONE-ID:publicIPZoneId": "118df98ffba182a9ca16b796c24dc45e95d60122645d82eb0d9c387f", "OS-EXT-STS:task_state": "spawning", "OS-EXT-STS:vm_state": "building", "flavor": {"id": "2", "links": [{"href": "https://dfw.servers.api.rackspacecloud.com/1025100/flavors/2", "rel": "bookmark"}]}, "id": "6f44aa9d-69a2-4874-b695-f088b2c3c700", "user_id": "a1f874751044405396a148b2787b8fc3", "name": "zs-itguys-dev.gotdns.com", "created": "2017-12-07T22:52:52Z", "tenant_id": "1025100", "OS-DCF:diskConfig": "MANUAL", "accessIPv4": "", "accessIPv6": "", "progress": 10, "OS-EXT-STS:power_state": 0, "config_drive": "", "metadata": {>>>}<<<}}syntax error, unexpected '}', expecting string literal Sleeping Syntax error at line 1: {"server": {"status": "BUILD", "updated": "2017-12-07T22:52:55Z", "hostId": "67dabd3c2cfdda50f92d62b056cfaaa2947bcfc31e651842bcb92728", "addresses": {"public": [{"version": 4, "addr": "192.237.214.196"}, {"version": 6, "addr": "2001:4800:7813:516:be76:4eff:fe04:d236"}], "private": [{"version": 4, "addr": "10.183.4.230"}]}, "links": [{"href": "https://dfw.servers.api.rackspacecloud.com/v2/1025100/servers/6f44aa9d-69a2-4874-b695-f088b2c3c700", "rel": "self"}, {"href": "https://dfw.servers.api.rackspacecloud.com/1025100/servers/6f44aa9d-69a2-4874-b695-f088b2c3c700", "rel": "bookmark"}], "key_name": "steve", "image": {"id": "59ab613b-8040-4a06-a5de-61a8a337b2c6", "links": [{"href": "https://dfw.servers.api.rackspacecloud.com/1025100/images/59ab613b-8040-4a06-a5de-61a8a337b2c6", "rel": "bookmark"}]}, "RAX-PUBLIC-IP-ZONE-ID:publicIPZoneId": "118df98ffba182a9ca16b796c24dc45e95d60122645d82eb0d9c387f", "OS-EXT-STS:task_state": "spawning", "OS-EXT-STS:vm_state": "building", "flavor": {"id": "2", "links": [{"href": "https://dfw.servers.api.rackspacecloud.com/1025100/flavors/2", "rel": "bookmark"}]}, "id": "6f44aa9d-69a2-4874-b695-f088b2c3c700", "user_id": "a1f874751044405396a148b2787b8fc3", "name": "zs-itguys-dev.gotdns.com", "created": "2017-12-07T22:52:52Z", "tenant_id": "1025100", "OS-DCF:diskConfig": "MANUAL", "accessIPv4": "", "accessIPv6": "", "progress": 10, "OS-EXT-STS:power_state": 0, "config_drive": "", "metadata": {>>>}<<<}}syntax error, unexpected '}', expecting string literal Sleeping  

pgibbs-openmake commented 6 years ago

Right, the error will still be thrown but it'll be caught by the catch block rather than throwing a runtime exception. I assume the "Syntax error at line 1" is what's coming out in red?

sbtaylor15 commented 6 years ago

​Correct. That should not be displayed since I am catching the exception.

Steve Taylor CITA and Co-Founder / OpenMake Software / tel: + 1.505.424.6439 x114 / mob: +1.505.920.6106

Follow us on: Blog https://www.openmakesoftware.com/insights/ / Twitter http://www.twitter.com/openmake/ Facebook https://www.facebook.com/pages/OpenMake-Software/478045172208305 / LinkedIn https://www.linkedin.com/in/steve-taylor-b539205 / YouTube https://www.youtube.com/channel/UCSgF51hv2Qy88POFsA59uJQ/ Google+ https://plus.google.com/u/0/+Openmakesoftware

Winners of the Jolt Award in Change and Configuration Management

On Thu, Dec 7, 2017 at 4:07 PM, pgibbs-openmake notifications@github.com wrote:

Right, the error will still be thrown but it'll be caught by the catch block rather than throwing a runtime exception. I assume the "Syntax error at line 1" is what's coming out in red?

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/OpenMake-Software/DeployHub-Pro/issues/233#issuecomment-350122472, or mute the thread https://github.com/notifications/unsubscribe-auth/AOI8TNz3ZqEkImwW8TdWMndvF2c5z_nlks5s-G-3gaJpZM4Q6S3E .