Skip to content

"vnctl interface add" should be rolled back on errors #524

@miz-axsh

Description

@miz-axsh

vnctl interface add command with duplicated port-name parameter inserts incomplete data into the database. The series of INSERT statements should be done in one transaction, and should be rolled back on errors.

Example:

# vnctl interfaces add \
        --uuid=if-inst1x \
        --mode=vif \
        --owner-datapath-uuid=dp-dp01 \
        --mac-address 10:54:ff:00:00:01 \
        --network-uuid=nw-test1 \
        --ipv4-address=10.100.0.10 \
        --port-name=inst1  # ← inst1

# vnctl interfaces add \
        --uuid=if-inst2x \
        --mode=vif \
        --owner-datapath-uuid=dp-dp01 \
        --mac-address 10:54:ff:00:00:02 \
        --network-uuid=nw-test1 \
        --ipv4-address=10.100.0.11 \
        --port-name=inst1  # ← mistake: violates uniqueness
---
:error: Sequel::UniqueConstraintViolation
:message: 'Mysql2::Error: Duplicate entry ''inst1-1-1-0'' for key ''port_name'''
:code: 500

got an error, because port-name is duplicated.

mysql> SELECT uuid FROM interfaces;
+--------+
| uuid   |
+--------+
| inst1x |
| inst2x |
+--------+
mysql> SELECT port_name FROM interface_ports;
+-----------+
| port_name |
+-----------+
| inst1     |
+-----------+

in spite of the error, new record was inserted into the interfaces table.

# vnctl interfaces add \
        --uuid=if-inst2x \
        --mode=vif \
        --owner-datapath-uuid=dp-dp01 \
        --mac-address 10:54:ff:00:00:02 \
        --network-uuid=nw-test1 \
        --ipv4-address=10.100.0.11 \
        --port-name=inst2  # now corrected
---
:error: Vnet::Endpoints::Errors::DuplicateUUID
:message: if-inst2x
:code: '102'

tried again with corrected port-name, still get error because of the inserted record.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions