Skip to content

Commit 11f5bd2

Browse files
Likitha Shettyprachi
authored andcommitted
CS-15145: Summary: ec2-register: need better error handling for negative cases.
The negative cases for which the error handling is improved, 1. run ec2-register with incorrect field separator for architecture parameter. 2. run ec2-register without providing required parameters.
1 parent b80c3dc commit 11f5bd2

2 files changed

Lines changed: 18 additions & 11 deletions

File tree

‎awsapi/src/com/cloud/bridge/service/core/ec2/EC2Engine.java‎

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1068,9 +1068,8 @@ public EC2CreateImageResponse registerImage(EC2RegisterImage request)
10681068
{
10691069
try {
10701070
CloudStackAccount caller = getCurrentAccount();
1071-
if (null == request.getFormat() || null == request.getName() || null == request.getOsTypeName() ||
1072-
null == request.getLocation() || null == request.getZoneName())
1073-
throw new EC2ServiceException(ServerError.InternalError, "Missing parameter - location/architecture/name");
1071+
if (null == request.getName())
1072+
throw new EC2ServiceException(ClientError.Unsupported, "Missing parameter - name");
10741073

10751074
List<CloudStackTemplate> templates = getApi().registerTemplate((request.getDescription() == null ? request.getName() : request.getDescription()),
10761075
request.getFormat(), request.getHypervisor(), request.getName(), toOSTypeId(request.getOsTypeName()), request.getLocation(),

‎awsapi/src/com/cloud/bridge/service/core/ec2/EC2RegisterImage.java‎

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,9 @@
1616
// under the License.
1717
package com.cloud.bridge.service.core.ec2;
1818

19+
import com.cloud.bridge.service.exception.EC2ServiceException;
20+
import com.cloud.bridge.service.exception.EC2ServiceException.ClientError;
21+
1922
public class EC2RegisterImage {
2023

2124
private String location;
@@ -67,14 +70,19 @@ public String getDescription() {
6770
*/
6871
public void setArchitecture( String param ) {
6972
if (null != param) {
70-
String parts[] = param.split( ":" );
71-
if (3 <= parts.length) {
72-
format = parts[0];
73-
zoneName = parts[1];
74-
osTypeName = parts[2];
75-
hypervisor = parts[3];
76-
}
77-
}
73+
if (!param.contains(":") || param.split(":").length < 4) {
74+
throw new EC2ServiceException( ClientError.InvalidParameterValue, "Supported format for " +
75+
"'architecture' is format:zonename:ostypename:hypervisor" );
76+
}
77+
String parts[] = param.split( ":" );
78+
format = parts[0];
79+
zoneName = parts[1];
80+
osTypeName = parts[2];
81+
hypervisor = parts[3];
82+
}
83+
else {
84+
throw new EC2ServiceException(ClientError.Unsupported, "Missing Parameter -" + " architecture");
85+
}
7886
}
7987

8088
public String getFormat() {

0 commit comments

Comments
 (0)