return NULL;
}
-static const struct nbrec_port_group *
-pg_by_name_or_uuid(struct ctl_context *ctx, const char *id, bool must_exist)
+static char * OVS_WARN_UNUSED_RESULT
+pg_by_name_or_uuid(struct ctl_context *ctx, const char *id, bool must_exist,
+ const struct nbrec_port_group **pg_p)
{
const struct nbrec_port_group *pg = NULL;
+ *pg_p = NULL;
struct uuid pg_uuid;
bool is_uuid = uuid_from_string(&pg_uuid, id);
}
if (!pg && must_exist) {
- ctl_fatal("%s: port group %s not found", id,
- is_uuid ? "UUID" : "name");
+ return xasprintf("%s: port group %s not found", id,
+ is_uuid ? "UUID" : "name");
}
- return pg;
+ *pg_p = pg;
+ return NULL;
}
static void
char *error;
if (!opt_type) {
- *pg = pg_by_name_or_uuid(ctx, ctx->argv[1], false);
+ error = pg_by_name_or_uuid(ctx, ctx->argv[1], false, pg);
+ if (error) {
+ return error;
+ }
error = ls_by_name_or_uuid(ctx, ctx->argv[1], false, ls);
if (error) {
return error;
ctx->argv[1]);
}
} else if (!strcmp(opt_type, "port-group")) {
- *pg = pg_by_name_or_uuid(ctx, ctx->argv[1], true);
+ error = pg_by_name_or_uuid(ctx, ctx->argv[1], true, pg);
+ if (error) {
+ return error;
+ }
*ls = NULL;
} else if (!strcmp(opt_type, "switch")) {
error = ls_by_name_or_uuid(ctx, ctx->argv[1], true, ls);
AT_CHECK([ovn-nbctl create port_group name=pg0], [0], [ignore])
OVN_NBCTL_TEST_ACL([pg0], [--type=port-group])
+dnl Test when port group doesn't exist
+AT_CHECK([ovn-nbctl --type=port-group acl-add pg1 to-lport 100 ip drop], [1], [], [dnl
+ovn-nbctl: pg1: port group name not found
+])
+
dnl Test when same name exists in logical switches and portgroups
AT_CHECK([ovn-nbctl create port_group name=ls0], [0], [ignore])
AT_CHECK([ovn-nbctl acl-add ls0 to-lport 100 ip drop], [1], [], [stderr])