Changes to address_active index means our host_id needs to be unique across the zone
This commit is contained in:
parent
289caa8225
commit
ccf187d710
@ -10,9 +10,9 @@ LOG_LEVEL=debug
|
|||||||
DB_CONNECTION=pgsql
|
DB_CONNECTION=pgsql
|
||||||
DB_HOST=postgres-test
|
DB_HOST=postgres-test
|
||||||
DB_PORT=5432
|
DB_PORT=5432
|
||||||
DB_DATABASE=postgres
|
DB_DATABASE=test
|
||||||
DB_USERNAME=postgres
|
DB_USERNAME=test
|
||||||
DB_PASSWORD=password
|
DB_PASSWORD=test
|
||||||
|
|
||||||
DB_MONGO_HOST=mongo
|
DB_MONGO_HOST=mongo
|
||||||
DB_MONGO_USERNAME=mongo
|
DB_MONGO_USERNAME=mongo
|
||||||
|
@ -10,7 +10,8 @@ test:
|
|||||||
alias: postgres-test
|
alias: postgres-test
|
||||||
|
|
||||||
variables:
|
variables:
|
||||||
POSTGRES_PASSWORD: password
|
POSTGRES_USER: test
|
||||||
|
POSTGRES_PASSWORD: test
|
||||||
|
|
||||||
tags:
|
tags:
|
||||||
- php
|
- php
|
||||||
|
@ -10,6 +10,8 @@ use App\Models\{Address,Domain,System,Zone};
|
|||||||
|
|
||||||
class NodeHierarchy extends Seeder
|
class NodeHierarchy extends Seeder
|
||||||
{
|
{
|
||||||
|
public const DEBUG=TRUE;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Run the database seeds.
|
* Run the database seeds.
|
||||||
*
|
*
|
||||||
@ -45,7 +47,7 @@ class NodeHierarchy extends Seeder
|
|||||||
private function hierarchy(Domain $domain,int $zoneid)
|
private function hierarchy(Domain $domain,int $zoneid)
|
||||||
{
|
{
|
||||||
$regions = [1,2];
|
$regions = [1,2];
|
||||||
$hosts = [0,1];
|
//$hosts = [20,30];
|
||||||
$hubs = [1000,2000];
|
$hubs = [1000,2000];
|
||||||
$nodes = [1,2,3];
|
$nodes = [1,2,3];
|
||||||
$hubnodes = [-1,+1];
|
$hubnodes = [-1,+1];
|
||||||
@ -63,6 +65,9 @@ class NodeHierarchy extends Seeder
|
|||||||
]);
|
]);
|
||||||
|
|
||||||
$zo = Zone::where('zone_id',$zoneid)->where('domain_id',$domain->id)->singleOrFail();
|
$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')
|
DB::table('addresses')
|
||||||
->insert([
|
->insert([
|
||||||
'zone_id'=>$zo->id,
|
'zone_id'=>$zo->id,
|
||||||
@ -77,8 +82,11 @@ class NodeHierarchy extends Seeder
|
|||||||
'updated_at'=>Carbon::now(),
|
'updated_at'=>Carbon::now(),
|
||||||
]);
|
]);
|
||||||
|
|
||||||
// Nodes
|
// ZC Nodes
|
||||||
foreach ($nodes as $nid) {
|
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));
|
$so = $this->system(sprintf('Node %03d:%03d/%03d.0@%s (ZC Node)',$zoneid,0,$nid,$domain->name));
|
||||||
DB::table('addresses')
|
DB::table('addresses')
|
||||||
->insert([
|
->insert([
|
||||||
@ -95,15 +103,22 @@ class NodeHierarchy extends Seeder
|
|||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (self::DEBUG)
|
||||||
|
dump(['end'=>'nodes top']);
|
||||||
|
|
||||||
// Regions
|
// Regions
|
||||||
foreach ($regions as $rid) {
|
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));
|
$so = $this->system(sprintf('Region %03d:%03d/%03d.0@%s',$zoneid,$rid,0,$domain->name));
|
||||||
DB::table('addresses')
|
DB::table('addresses')
|
||||||
->insert([
|
->insert([
|
||||||
'zone_id'=>$zo->id,
|
'zone_id'=>$zo->id,
|
||||||
'active'=>TRUE,
|
'active'=>TRUE,
|
||||||
'region_id'=>$rid,
|
'region_id'=>$rid,
|
||||||
'host_id'=>0,
|
'host_id'=>$rid,
|
||||||
'node_id'=>0,
|
'node_id'=>0,
|
||||||
'point_id'=>0,
|
'point_id'=>0,
|
||||||
'system_id'=>$so->id,
|
'system_id'=>$so->id,
|
||||||
@ -112,15 +127,18 @@ class NodeHierarchy extends Seeder
|
|||||||
'updated_at'=>Carbon::now(),
|
'updated_at'=>Carbon::now(),
|
||||||
]);
|
]);
|
||||||
|
|
||||||
// Nodes
|
// RC Nodes
|
||||||
foreach ($nodes as $nid) {
|
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));
|
$so = $this->system(sprintf('Node %03d:%03d/%03d.0@%s (RC Node)',$zoneid,$rid,$nid,$domain->name));
|
||||||
DB::table('addresses')
|
DB::table('addresses')
|
||||||
->insert([
|
->insert([
|
||||||
'zone_id'=>$zo->id,
|
'zone_id'=>$zo->id,
|
||||||
'active'=>TRUE,
|
'active'=>TRUE,
|
||||||
'region_id'=>$rid,
|
'region_id'=>$rid,
|
||||||
'host_id'=>0,
|
'host_id'=>$rid,
|
||||||
'node_id'=>$nid,
|
'node_id'=>$nid,
|
||||||
'point_id'=>0,
|
'point_id'=>0,
|
||||||
'system_id'=>$so->id,
|
'system_id'=>$so->id,
|
||||||
@ -129,11 +147,16 @@ class NodeHierarchy extends Seeder
|
|||||||
'updated_at'=>Carbon::now(),
|
'updated_at'=>Carbon::now(),
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
|
dump(['end'=>'NODES regions']);
|
||||||
|
|
||||||
// Hosts
|
// Hosts
|
||||||
foreach ($hosts as $hid) {
|
foreach ($regions as $rrid) {
|
||||||
$hostid = $rid*10+$hid;
|
$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));
|
$so = $this->system(sprintf('Host %03d:%03d/0.0@%s (Region %03d)',$zoneid,$hostid,$domain->name,$rid));
|
||||||
|
|
||||||
DB::table('addresses')
|
DB::table('addresses')
|
||||||
->insert([
|
->insert([
|
||||||
'zone_id'=>$zo->id,
|
'zone_id'=>$zo->id,
|
||||||
@ -150,6 +173,9 @@ class NodeHierarchy extends Seeder
|
|||||||
|
|
||||||
// Nodes
|
// Nodes
|
||||||
foreach ($nodes as $nid) {
|
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));
|
$so = $this->system(sprintf('Node %03d:%03d/%03d.0@%s (Region %03d) - Host Node',$zoneid,$hostid,$nid,$domain->name,$rid));
|
||||||
DB::table('addresses')
|
DB::table('addresses')
|
||||||
->insert([
|
->insert([
|
||||||
@ -203,7 +229,10 @@ class NodeHierarchy extends Seeder
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
dump(['end'=>'NODES normal']);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
dump(['end'=>'heirarchy']);
|
||||||
}
|
}
|
||||||
|
|
||||||
private function system(string $name): System
|
private function system(string $name): System
|
||||||
|
@ -46,7 +46,7 @@ class RoutingTest extends TestCase
|
|||||||
$ao = Address::findFTN('100:10/0@domain-a');
|
$ao = Address::findFTN('100:10/0@domain-a');
|
||||||
$this->assertEquals($ao->role,Address::NODE_NC);
|
$this->assertEquals($ao->role,Address::NODE_NC);
|
||||||
$this->assertEquals('100:0/0.0@domain-a',$ao->parent()->ftn);
|
$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($ao->role,Address::NODE_ACTIVE);
|
||||||
$this->assertEquals('100:0/0.0@domain-a',$ao->parent()->ftn);
|
$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);
|
$this->assertEquals('100:10/0.0@domain-a',$ao->parent()->ftn);
|
||||||
|
|
||||||
// Pick a Node and we have 1 less child
|
// 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);
|
$this->assertEquals($ao->role,Address::NODE_ACTIVE);
|
||||||
$ao->system->sessions()->attach([$ao->zone_id=>['sespass'=>'ABCD']]);
|
$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);
|
$this->assertNULL($ao->children);
|
||||||
$ao = Address::findFTN('100:0/0@domain-a');
|
$ao = Address::findFTN('100:0/0@domain-a');
|
||||||
$this->assertCount(40,$ao->children);
|
$this->assertCount(40,$ao->children);
|
||||||
|
|
||||||
// Define address on a HC and we have 3 less 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);
|
$this->assertEquals($ao->role,Address::NODE_HC);
|
||||||
$ao->system->sessions()->attach([$ao->zone_id=>['sespass'=>'ABCD']]);
|
$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);
|
$this->assertCount(2,$ao->children);
|
||||||
$ao = Address::findFTN('100:0/0@domain-a');
|
$ao = Address::findFTN('100:0/0@domain-a');
|
||||||
$this->assertCount(37,$ao->children);
|
$this->assertCount(37,$ao->children);
|
||||||
|
Loading…
Reference in New Issue
Block a user