File: 081-unique-id-create.t

package info (click to toggle)
libvirt-tck 0.1.0~2.git890d1c-1
  • links: PTS, VCS
  • area: main
  • in suites: experimental
  • size: 1,128 kB
  • sloc: perl: 2,885; sh: 1,180; xml: 992; makefile: 6
file content (124 lines) | stat: -rw-r--r-- 4,159 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
# -*- perl -*-
#
# Copyright (C) 2009 Red Hat, Inc.
# Copyright (C) 2009 Daniel P. Berrange
#
# This program is free software; You can redistribute it and/or modify
# it under the GNU General Public License as published by the Free
# Software Foundation; either version 2, or (at your option) any
# later version
#
# The file "LICENSE" distributed along with this file provides full
# details of the terms and conditions
#

=pod

=head1 NAME

network/081-unique-id-create.t - Unique identifier checking at create

=head1 DESCRIPTION

The test case validates the unique identifiers are being
validated for uniqueness, and appropriate errors raised
upon error.

 - If existing VM has same UUID
      - If name also matches
           - If existing VM is running => raise error
           - Else => allow
      - Else => raise error

 - Else
      - If name matches => raise error
      - Else => allow

=cut

use strict;
use warnings;

use Test::More tests => 12;

use Sys::Virt::TCK;

my $tck = Sys::Virt::TCK->new();
my $conn = eval { $tck->setup(); };
BAIL_OUT "failed to setup test harness: $@" if $@;
END { $tck->cleanup if $tck; }

my $name1 = "tck1";
my $name2 = "tck2";
my $uuid1 = "11111111-1111-1111-1111-111111111111";
my $uuid2 = "22222222-1111-1111-1111-111111111111";

# The initial config
my $xml = $tck->generic_network($name1)->uuid($uuid1)->as_xml;
# One with a different UUID, matching name
my $xml_diffuuid = $tck->generic_network($name1)->uuid($uuid2)->as_xml;
# One with a matching UUID, different name
my $xml_diffname = $tck->generic_network($name2)->uuid($uuid1)->as_xml;
# One with a different UUID, different name
my $xml_diffboth = $tck->generic_network($name2)->uuid($uuid2)->as_xml;

diag "Defining persistent network config";
my ($dom, $dom1);
ok_network(sub { $dom = $conn->define_network($xml) }, "defined persistent network", $name1);
#$dom->DESTROY;

diag "Trying to create a active network with same name, same UUID";
ok_network(sub { $dom = $conn->create_network($xml) }, "created persistent network again", $name1);
$dom->destroy;

diag "Trying to create a active network with same UUID, different name";
ok_error(sub { $conn->create_network($xml_diffname) }, "error raised from duplicate network");

diag "Trying to create a active network with different UUID, same name";
ok_error(sub { $conn->create_network($xml_diffuuid) }, "error raised from duplicate network");

diag "Trying to create a active network with different UUID, different name";
ok_network(sub { $dom1 = $conn->create_network($xml_diffboth) }, "created transient network", $name2);

diag "Destroying active transient network";
$dom1->destroy;
#$dom->DESTROY;


diag "Checking that network has now gone";
ok_error(sub { $conn->get_network_by_name($name2) }, "NO_network error raised from undefined network",
	 Sys::Virt::Error::ERR_NO_NETWORK);


diag "Starting persistent network config";
$dom->create();
#$dom->DESTROY;

diag "Trying to create a active network with same name, same UUID";
ok_error(sub { $dom = $conn->create_network($xml) }, "cannot create already running network");

diag "Trying to create a active network with same UUID, different name";
ok_error(sub { $dom = $conn->create_network($xml_diffname) }, "error raised from duplicate network");

diag "Trying to create a active network with different UUID, same name";
ok_error(sub { $dom = $conn->create_network($xml_diffuuid) }, "error raised from duplicate network");

diag "Trying to create a active network with different UUID, different name";
ok_network(sub { $dom1 = $conn->create_network($xml_diffboth) }, "created persistent network", $name2);

diag "Destroying transient network config";
$dom1->destroy;
#$dom->DESTROY;


diag "Checking that network has now gone";
ok_error(sub { $conn->get_network_by_name($name2) }, "NO_network error raised from undefined network",
	 Sys::Virt::Error::ERR_NO_NETWORK);

diag "Stopping & undefining persistent network config";
$dom->destroy;
$dom->undefine;
diag "Checking that network has now gone";
ok_error(sub { $conn->get_network_by_name($name1) }, "NO_network error raised from undefined network",
	 Sys::Virt::Error::ERR_NO_NETWORK);