Changes to address_active index means our host_id needs to be unique across the zone

This commit is contained in:
Deon George 2022-11-20 00:19:09 +11:00
parent 289caa8225
commit ccf187d710
4 changed files with 46 additions and 16 deletions

View File

@ -10,9 +10,9 @@ LOG_LEVEL=debug
DB_CONNECTION=pgsql
DB_HOST=postgres-test
DB_PORT=5432
DB_DATABASE=postgres
DB_USERNAME=postgres
DB_PASSWORD=password
DB_DATABASE=test
DB_USERNAME=test
DB_PASSWORD=test
DB_MONGO_HOST=mongo
DB_MONGO_USERNAME=mongo

View File

@ -10,7 +10,8 @@ test:
alias: postgres-test
variables:
POSTGRES_PASSWORD: password
POSTGRES_USER: test
POSTGRES_PASSWORD: test
tags:
- php

View File

@ -10,6 +10,8 @@ use App\Models\{Address,Domain,System,Zone};
class NodeHierarchy extends Seeder
{
public const DEBUG=TRUE;
/**
* Run the database seeds.
*
@ -45,7 +47,7 @@ class NodeHierarchy extends Seeder
private function hierarchy(Domain $domain,int $zoneid)
{
$regions = [1,2];
$hosts = [0,1];
//$hosts = [20,30];
$hubs = [1000,2000];
$nodes = [1,2,3];
$hubnodes = [-1,+1];
@ -63,6 +65,9 @@ class NodeHierarchy extends Seeder
]);
$zo = Zone::where('zone_id',$zoneid)->where('domain_id',$domain->id)->singleOrFail();
if (self::DEBUG)
dump(['zo'=>$zo->zone_id,'rid'=>0,'hid'=>0,'nid'=>0]);
DB::table('addresses')
->insert([
'zone_id'=>$zo->id,
@ -77,8 +82,11 @@ class NodeHierarchy extends Seeder
'updated_at'=>Carbon::now(),
]);
// Nodes
// ZC Nodes
foreach ($nodes as $nid) {
if (self::DEBUG)
dump(['rid'=>$zo->zone_id,'hid'=>$zo->zone_id,'nid'=>$nid]);
$so = $this->system(sprintf('Node %03d:%03d/%03d.0@%s (ZC Node)',$zoneid,0,$nid,$domain->name));
DB::table('addresses')
->insert([
@ -95,15 +103,22 @@ class NodeHierarchy extends Seeder
]);
}
if (self::DEBUG)
dump(['end'=>'nodes top']);
// Regions
foreach ($regions as $rid) {
$hostid = $rid;
if (self::DEBUG)
dump(['rid'=>$rid,'hid'=>$hostid,'nid'=>0]);
$so = $this->system(sprintf('Region %03d:%03d/%03d.0@%s',$zoneid,$rid,0,$domain->name));
DB::table('addresses')
->insert([
'zone_id'=>$zo->id,
'active'=>TRUE,
'region_id'=>$rid,
'host_id'=>0,
'host_id'=>$rid,
'node_id'=>0,
'point_id'=>0,
'system_id'=>$so->id,
@ -112,15 +127,18 @@ class NodeHierarchy extends Seeder
'updated_at'=>Carbon::now(),
]);
// Nodes
// RC Nodes
foreach ($nodes as $nid) {
if (self::DEBUG)
dump(['rid'=>$rid,'hid'=>$hostid,'nid'=>$nid]);
$so = $this->system(sprintf('Node %03d:%03d/%03d.0@%s (RC Node)',$zoneid,$rid,$nid,$domain->name));
DB::table('addresses')
->insert([
'zone_id'=>$zo->id,
'active'=>TRUE,
'region_id'=>$rid,
'host_id'=>0,
'host_id'=>$rid,
'node_id'=>$nid,
'point_id'=>0,
'system_id'=>$so->id,
@ -129,11 +147,16 @@ class NodeHierarchy extends Seeder
'updated_at'=>Carbon::now(),
]);
}
dump(['end'=>'NODES regions']);
// Hosts
foreach ($hosts as $hid) {
$hostid = $rid*10+$hid;
foreach ($regions as $rrid) {
$hostid = $rid*10+$rrid-1;
if (self::DEBUG)
dump(['rid'=>$rid,'hid'=>$hostid,'nid'=>0]);
$so = $this->system(sprintf('Host %03d:%03d/0.0@%s (Region %03d)',$zoneid,$hostid,$domain->name,$rid));
DB::table('addresses')
->insert([
'zone_id'=>$zo->id,
@ -150,6 +173,9 @@ class NodeHierarchy extends Seeder
// Nodes
foreach ($nodes as $nid) {
if (self::DEBUG)
dump(['rid'=>$rid,'hid'=>$hostid,'nid'=>$nid]);
$so = $this->system(sprintf('Node %03d:%03d/%03d.0@%s (Region %03d) - Host Node',$zoneid,$hostid,$nid,$domain->name,$rid));
DB::table('addresses')
->insert([
@ -203,7 +229,10 @@ class NodeHierarchy extends Seeder
}
}
}
dump(['end'=>'NODES normal']);
}
dump(['end'=>'heirarchy']);
}
private function system(string $name): System

View File

@ -46,7 +46,7 @@ class RoutingTest extends TestCase
$ao = Address::findFTN('100:10/0@domain-a');
$this->assertEquals($ao->role,Address::NODE_NC);
$this->assertEquals('100:0/0.0@domain-a',$ao->parent()->ftn);
$ao = Address::findFTN('100:21/2001.0@domain-a');
$ao = Address::findFTN('100:11/2001.0@domain-a');
$this->assertEquals($ao->role,Address::NODE_ACTIVE);
$this->assertEquals('100:0/0.0@domain-a',$ao->parent()->ftn);
@ -68,19 +68,19 @@ class RoutingTest extends TestCase
$this->assertEquals('100:10/0.0@domain-a',$ao->parent()->ftn);
// Pick a Node and we have 1 less child
$ao = Address::findFTN('100:21/2001.0@domain-a');
$ao = Address::findFTN('100:11/2001.0@domain-a');
$this->assertEquals($ao->role,Address::NODE_ACTIVE);
$ao->system->sessions()->attach([$ao->zone_id=>['sespass'=>'ABCD']]);
$ao = Address::findFTN('100:21/2001.0@domain-a');
$ao = Address::findFTN('100:11/2001.0@domain-a');
$this->assertNULL($ao->children);
$ao = Address::findFTN('100:0/0@domain-a');
$this->assertCount(40,$ao->children);
// Define address on a HC and we have 3 less children
$ao = Address::findFTN('100:21/1000.0@domain-a');
$ao = Address::findFTN('100:11/1000.0@domain-a');
$this->assertEquals($ao->role,Address::NODE_HC);
$ao->system->sessions()->attach([$ao->zone_id=>['sespass'=>'ABCD']]);
$ao = Address::findFTN('100:21/1000.0@domain-a');
$ao = Address::findFTN('100:11/1000.0@domain-a');
$this->assertCount(2,$ao->children);
$ao = Address::findFTN('100:0/0@domain-a');
$this->assertCount(37,$ao->children);