Skip to content

Commit 9dd7eb9

Browse files
committed
Switch to modern network attributes
1 parent 6cc717c commit 9dd7eb9

7 files changed

Lines changed: 57 additions & 35 deletions

File tree

igvm/commands.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -295,8 +295,11 @@ def change_address(
295295
)
296296

297297
new_address = ip_address(new_address)
298+
new_address_attr = 'ipv6'
299+
if new_address.version == 4:
300+
new_address_attr = 'ipv4'
298301

299-
if vm.dataset_obj['intern_ip'] == new_address:
302+
if vm.dataset_obj[new_address_attr] == new_address:
300303
raise ConfigError('New IP address is the same as the old one!')
301304

302305
if not vm.hypervisor.get_vlan_network(new_address) and not migrate:
@@ -859,7 +862,8 @@ def host_info(vm_hostname):
859862
'status',
860863
)),
861864
('Network', (
862-
'intern_ip',
865+
'ipv4',
866+
'ipv6',
863867
'mac_address',
864868
)),
865869
('Resources', (

igvm/drbd.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -185,7 +185,7 @@ def get_host_config(self):
185185
' }}'
186186
.format(
187187
host=self.hv.dataset_obj['hostname'],
188-
addr=self.hv.dataset_obj['intern_ip'],
188+
addr=self.hv.dataset_obj['ipv6'],
189189
port=self.get_device_port(),
190190
dm_minor=self.get_device_minor(),
191191
lv_name=self.lv_name,

igvm/hypervisor.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -212,7 +212,7 @@ def check_vm(self, vm, offline):
212212
)
213213

214214
# Proper VLAN?
215-
if not self.get_vlan_network(vm.dataset_obj['intern_ip']):
215+
if not self.get_vlan_network(vm.dataset_obj['ipv6']):
216216
raise HypervisorError(
217217
'Hypervisor "{}" does not support route_network "{}".'
218218
.format(self.fqdn, vm.route_network)

igvm/kvm.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -388,7 +388,9 @@ def generate_domain_xml(hypervisor, vm):
388388
# VM, instead the VM is updated to the latest settings.
389389
# Every KVM setting should be configurable via Serveradmin anyway.
390390
props = DomainProperties(hypervisor, vm)
391-
vlan_network = hypervisor.get_vlan_network(vm.dataset_obj['intern_ip'])
391+
vlan_network = hypervisor.get_vlan_network(
392+
vm.dataset_obj.get('ipv6') or vm.dataset_obj.get('ipv4')
393+
)
392394

393395
config = {
394396
'name': vm.uid_name,

igvm/settings.py

Lines changed: 12 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -118,31 +118,34 @@
118118

119119
IMAGE_PATH = '/tmp'
120120

121+
HOST_ATTRIBUTES = [
122+
'environment',
123+
'hostname',
124+
'igvm_locked',
125+
'ipv4',
126+
'ipv6',
127+
'os',
128+
'state',
129+
]
130+
121131
NETWORK_ATTRIBUTES = [
122132
'hostname',
123133
'service_groups',
124134
]
125135

126-
HYPERVISOR_ATTRIBUTES = [
136+
HYPERVISOR_ATTRIBUTES = HOST_ATTRIBUTES + [
127137
'ceph_disks',
128138
'cpu_perffactor',
129139
'cpu_util_pct',
130-
'environment',
131140
'hardware_model',
132-
'hostname',
133-
'igvm_locked',
134141
'igvm_migration_log',
135-
'intern_ip',
136142
'iops_avg',
137-
'igvm_migration_log',
138143
'libvirt_memory_total_gib',
139144
'libvirt_memory_used_gib',
140145
'libvirt_pool_total_gib',
141146
'libvirt_pool_used_gib',
142147
'num_cpu',
143-
'os',
144148
{'route_network': NETWORK_ATTRIBUTES},
145-
'state',
146149
{
147150
'vlan_networks': [
148151
'hostname',
@@ -169,7 +172,7 @@
169172
},
170173
]
171174

172-
VM_ATTRIBUTES = [
175+
VM_ATTRIBUTES = HOST_ATTRIBUTES + [
173176
'aws_image_id',
174177
'aws_instance_id',
175178
'aws_instance_type',
@@ -180,22 +183,16 @@
180183
'datacenter',
181184
'datacenter_type',
182185
'disk_size_gib',
183-
'environment',
184186
'function',
185187
'game_market',
186188
'game_type',
187189
'game_world',
188-
'hostname',
189-
'igvm_locked',
190-
'intern_ip',
191190
'io_weight',
192191
'libvirt_pool_override',
193192
'load_99',
194193
'mac',
195194
'memory',
196195
'num_cpu',
197-
'os',
198-
'primary_ip6',
199196
'project',
200197
{'project_network': NETWORK_ATTRIBUTES},
201198
'puppet_ca',
@@ -205,7 +202,6 @@
205202
'served_game',
206203
'service_groups',
207204
'sshfp',
208-
'state',
209205
{'hypervisor': HYPERVISOR_ATTRIBUTES},
210206
]
211207

igvm/vm.py

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -363,7 +363,7 @@ def start(self, force_stop_failed=True, transaction=None):
363363
raise VMError('VM did not come online in time')
364364

365365
host_up = wait_until(
366-
str(self.dataset_obj['intern_ip']),
366+
str(self.dataset_obj['ipv6']),
367367
waitmsg='Waiting for SSH to respond',
368368
)
369369
if not host_up and force_stop_failed:
@@ -408,7 +408,7 @@ def aws_start(self):
408408
raise VMError(e)
409409

410410
host_up = wait_until(
411-
str(self.dataset_obj['intern_ip']),
411+
str(self.dataset_obj['ipv6']),
412412
waitmsg='Waiting for SSH to respond',
413413
)
414414

@@ -431,7 +431,7 @@ def aws_restart(self):
431431
raise VMError(e)
432432

433433
host_up = wait_until(
434-
str(self.dataset_obj['intern_ip']),
434+
str(self.dataset_obj['ipv6']),
435435
waitmsg='Waiting for SSH to respond',
436436
timeout=180
437437
)
@@ -647,7 +647,8 @@ def disk_free(self):
647647
def info(self):
648648
result = {
649649
'hypervisor': self.hypervisor.fqdn,
650-
'intern_ip': self.dataset_obj['intern_ip'],
650+
'ipv4': self.dataset_obj['ipv4'],
651+
'ipv6': self.dataset_obj['ipv6'],
651652
'num_cpu': self.dataset_obj['num_cpu'],
652653
'memory': self.dataset_obj['memory'],
653654
'disk_size_gib': self.dataset_obj['disk_size_gib'],
@@ -807,8 +808,8 @@ def aws_build(self,
807808
self.dataset_obj['aws_placement']
808809
)
809810
},
810-
PrivateIpAddress=str(self.dataset_obj['intern_ip']),
811-
Ipv6Addresses=[{'Ipv6Address':str(self.dataset_obj['primary_ip6'])}],
811+
PrivateIpAddress=str(self.dataset_obj['ipv4']),
812+
Ipv6Addresses=[{'Ipv6Address':str(self.dataset_obj['ipv6'])}],
812813
UserData='' if postboot is None else postboot,
813814
TagSpecifications=[
814815
{
@@ -1045,16 +1046,19 @@ def copy_postboot_script(self, script):
10451046
self.put('/buildvm-postboot', script, '0755')
10461047

10471048
def restore_address(self):
1048-
self.dataset_obj['intern_ip'] = self.old_address
1049+
self.dataset_obj['ipv4'] = self.old_address_ipv4
1050+
self.dataset_obj['ipv6'] = self.old_address_ipv6
10491051
self.dataset_obj.commit()
10501052
self.route_network = self.old_network
10511053

1052-
def change_address(self, new_address, new_network, transaction=None):
1054+
def change_address(self, new_address_ipv4, new_address_ipv6, new_network, transaction=None):
10531055
# All queries to Serveradmin are kept in commands.py.
10541056
# That's why this metod receives both new address and new network.
1055-
self.old_address = self.dataset_obj['intern_ip']
1057+
self.old_address_ipv4 = self.dataset_obj['ipv4']
1058+
self.old_address_ipv6 = self.dataset_obj['ipv6']
10561059
self.old_network = self.route_network
1057-
self.dataset_obj['intern_ip'] = new_address
1060+
self.dataset_obj['ipv4'] = new_address_ipv4
1061+
self.dataset_obj['ipv6'] = new_address_ipv6
10581062
self.dataset_obj.commit()
10591063
self.route_network = new_network
10601064

tests/test_integration.py

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111

1212
from adminapi import api
1313
from adminapi.dataset import Query
14-
from adminapi.filters import Any
14+
from adminapi.filters import Any, Not
1515
from fabric.api import env
1616
from fabric.network import disconnect_all
1717
from mock import patch
@@ -731,12 +731,28 @@ def test_new_address(self):
731731
# We don't have a way to ask for new IP address from Serveradmin
732732
# and lock it for us. The method below will usually work fine.
733733
# When it starts failing, we must develop retry method.
734-
new_address = get_next_address(VM_NET, 2, 'ipv4')
734+
735+
# First figure out if the network in which the tests are run
736+
# is IPv6-only or dual-stack. For dual-stack networks we must
737+
# use IPv4 and IPv6 will be auto-assigned.
738+
ip_attr = 'ipv4'
739+
test_net = Query(
740+
{
741+
'servertype': 'route_network',
742+
'state': Not('retired'),
743+
'hostname': VM_NET,
744+
},
745+
['hostname', 'ipv4', 'ipv6'],
746+
).get()
747+
if not test_net['ipv4']:
748+
ip_attr = 'ipv6'
749+
750+
new_address = get_next_address(VM_NET, 2, ip_attr)
735751

736752
change_address(VM_HOSTNAME, new_address, offline=True)
737753

738-
obj = Query({'hostname': VM_HOSTNAME}, ['intern_ip']).get()
739-
self.assertEqual(obj['intern_ip'], new_address)
754+
obj = Query({'hostname': VM_HOSTNAME}, [ip_attr]).get()
755+
self.assertEqual(obj[ip_attr], new_address)
740756
with _get_vm(VM_HOSTNAME) as vm:
741757
vm.run(cmd('ip a | grep {}', new_address))
742758
self.check_vm_present()

0 commit comments

Comments
 (0)