From ccf187d710dba4d560fe3e8afbd0b7f2c9eeb1e6 Mon Sep 17 00:00:00 2001 From: Deon George Date: Sun, 20 Nov 2022 00:19:09 +1100 Subject: [PATCH] Changes to address_active index means our host_id needs to be unique across the zone --- .env.testing | 6 ++--- .gitlab-test.yml | 3 ++- database/seeders/NodeHierarchy.php | 43 +++++++++++++++++++++++++----- tests/Feature/RoutingTest.php | 10 +++---- 4 files changed, 46 insertions(+), 16 deletions(-) diff --git a/.env.testing b/.env.testing index a69fdb1..6d825f8 100644 --- a/.env.testing +++ b/.env.testing @@ -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 diff --git a/.gitlab-test.yml b/.gitlab-test.yml index 0974b7d..cc42f63 100644 --- a/.gitlab-test.yml +++ b/.gitlab-test.yml @@ -10,7 +10,8 @@ test: alias: postgres-test variables: - POSTGRES_PASSWORD: password + POSTGRES_USER: test + POSTGRES_PASSWORD: test tags: - php diff --git a/database/seeders/NodeHierarchy.php b/database/seeders/NodeHierarchy.php index 5a82885..82578a3 100644 --- a/database/seeders/NodeHierarchy.php +++ b/database/seeders/NodeHierarchy.php @@ -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 diff --git a/tests/Feature/RoutingTest.php b/tests/Feature/RoutingTest.php index 3dc29ac..3abca1d 100644 --- a/tests/Feature/RoutingTest.php +++ b/tests/Feature/RoutingTest.php @@ -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);