LEFT | RIGHT |
1 // launchpad.net/juju/go/state | |
2 // | |
3 // Copyright (c) 2011-2012 Canonical Ltd. | |
4 package state | 1 package state |
5 | 2 |
6 import ( | 3 import ( |
7 . "launchpad.net/gocheck" | 4 . "launchpad.net/gocheck" |
8 "launchpad.net/goyaml" | 5 "launchpad.net/goyaml" |
9 "launchpad.net/gozk/zookeeper" | 6 "launchpad.net/gozk/zookeeper" |
10 ) | 7 ) |
11 | 8 |
12 type TopologySuite struct { | 9 type TopologySuite struct { |
13 zkServer *zookeeper.Server | 10 zkServer *zookeeper.Server |
(...skipping 440 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
454 | 451 |
455 func (s *TopologySuite) TestRelation(c *C) { | 452 func (s *TopologySuite) TestRelation(c *C) { |
456 // Check that the retrieving of relations works correctly. | 453 // Check that the retrieving of relations works correctly. |
457 relation, err := s.t.Relation("r-1") | 454 relation, err := s.t.Relation("r-1") |
458 c.Assert(relation, IsNil) | 455 c.Assert(relation, IsNil) |
459 c.Assert(err, ErrorMatches, `relation "r-1" does not exist`) | 456 c.Assert(err, ErrorMatches, `relation "r-1" does not exist`) |
460 s.t.AddService("s-p", "riak") | 457 s.t.AddService("s-p", "riak") |
461 s.t.AddRelation("r-1", &zkRelation{ | 458 s.t.AddRelation("r-1", &zkRelation{ |
462 Interface: "ifce", | 459 Interface: "ifce", |
463 Scope: ScopeGlobal, | 460 Scope: ScopeGlobal, |
464 » » Services: map[RelationRole]string{RolePeer: "s-p"}, | 461 » » Services: map[RelationRole]*zkRelationService{RolePeer: &zkRela
tionService{"s-p", "cache"}}, |
465 }) | 462 }) |
466 relation, err = s.t.Relation("r-1") | 463 relation, err = s.t.Relation("r-1") |
467 c.Assert(err, IsNil) | 464 c.Assert(err, IsNil) |
468 c.Assert(relation, NotNil) | 465 c.Assert(relation, NotNil) |
469 » c.Assert(relation.Services[RolePeer], Equals, "s-p") | 466 » c.Assert(relation.Services[RolePeer].Service, Equals, "s-p") |
470 } | 467 } |
471 | 468 |
472 func (s *TopologySuite) TestAddRelation(c *C) { | 469 func (s *TopologySuite) TestAddRelation(c *C) { |
473 // Check that adding a relation works and can only be done once and with········ | 470 // Check that adding a relation works and can only be done once and with········ |
474 // valid services. | 471 // valid services. |
475 relation, err := s.t.Relation("r-1") | 472 relation, err := s.t.Relation("r-1") |
476 c.Assert(relation, IsNil) | 473 c.Assert(relation, IsNil) |
477 c.Assert(err, ErrorMatches, `relation "r-1" does not exist`) | 474 c.Assert(err, ErrorMatches, `relation "r-1" does not exist`) |
478 s.t.AddService("s-p", "mysql") | 475 s.t.AddService("s-p", "mysql") |
479 s.t.AddService("s-r", "wordpress") | 476 s.t.AddService("s-r", "wordpress") |
480 err = s.t.AddRelation("r-1", &zkRelation{ | 477 err = s.t.AddRelation("r-1", &zkRelation{ |
481 Interface: "ifce", | 478 Interface: "ifce", |
482 Scope: ScopeGlobal, | 479 Scope: ScopeGlobal, |
483 » » Services: map[RelationRole]string{RoleProvider: "s-p", RoleRequ
irer: "s-r"}, | 480 » » Services: map[RelationRole]*zkRelationService{ |
| 481 » » » RoleProvider: &zkRelationService{"s-p", "db"}, |
| 482 » » » RoleRequirer: &zkRelationService{"s-r", "db"}, |
| 483 » » }, |
484 }) | 484 }) |
485 c.Assert(err, IsNil) | 485 c.Assert(err, IsNil) |
486 relation, err = s.t.Relation("r-1") | 486 relation, err = s.t.Relation("r-1") |
487 c.Assert(err, IsNil) | 487 c.Assert(err, IsNil) |
488 c.Assert(relation, NotNil) | 488 c.Assert(relation, NotNil) |
489 » c.Assert(relation.Services[RoleProvider], Equals, "s-p") | 489 » c.Assert(relation.Services[RoleProvider].Service, Equals, "s-p") |
490 » c.Assert(relation.Services[RoleRequirer], Equals, "s-r") | 490 » c.Assert(relation.Services[RoleRequirer].Service, Equals, "s-r") |
491 | 491 |
492 err = s.t.AddRelation("r-2", &zkRelation{ | 492 err = s.t.AddRelation("r-2", &zkRelation{ |
493 Interface: "", | 493 Interface: "", |
494 Scope: ScopeGlobal, | 494 Scope: ScopeGlobal, |
495 » » Services: map[RelationRole]string{RoleProvider: "s-p", RoleRequ
irer: "s-r"}, | 495 » » Services: map[RelationRole]*zkRelationService{ |
| 496 » » » RoleProvider: &zkRelationService{"s-p", "db"}, |
| 497 » » » RoleRequirer: &zkRelationService{"s-r", "db"}, |
| 498 » » }, |
496 }) | 499 }) |
497 c.Assert(err, ErrorMatches, `relation interface is empty`) | 500 c.Assert(err, ErrorMatches, `relation interface is empty`) |
498 | 501 |
499 » err = s.t.AddRelation("r-2", &zkRelation{ | 502 » err = s.t.AddRelation("r-3", &zkRelation{ |
500 » » Interface: "ifce", | 503 » » Interface: "ifce", |
501 » » Scope: ScopeGlobal, | 504 » » Scope: ScopeGlobal, |
502 » » Services: map[RelationRole]string{}, | 505 » » Services: map[RelationRole]*zkRelationService{}, |
503 » }) | 506 » }) |
504 » c.Assert(err, ErrorMatches, `no service defined`) | 507 » c.Assert(err, ErrorMatches, `relation has no services`) |
505 | 508 |
506 » err = s.t.AddRelation("r-2", &zkRelation{ | 509 » err = s.t.AddRelation("r-4", &zkRelation{ |
507 » » Interface: "ifce", | 510 » » Interface: "ifce", |
508 » » Scope: ScopeGlobal, | 511 » » Scope: ScopeGlobal, |
509 » » Services: map[RelationRole]string{RoleProvider: "s-p"}, | 512 » » Services: map[RelationRole]*zkRelationService{ |
510 » }) | 513 » » » RoleProvider: &zkRelationService{"s-p", "db"}, |
511 » c.Assert(err, ErrorMatches, `provider or consumer service missing`) | 514 » » }, |
512 | 515 » }) |
513 » err = s.t.AddRelation("r-2", &zkRelation{ | 516 » c.Assert(err, ErrorMatches, `relation has provider but no requirer`) |
514 » » Interface: "ifce", | 517 |
515 » » Scope: ScopeGlobal, | 518 » err = s.t.AddRelation("r-5", &zkRelation{ |
516 » » Services: map[RelationRole]string{RoleProvider: "s-p", RolePeer
: "s-r"}, | 519 » » Interface: "ifce", |
517 » }) | 520 » » Scope: ScopeGlobal, |
518 » c.Assert(err, ErrorMatches, `mixed peer with provider or consumer servic
e`) | 521 » » Services: map[RelationRole]*zkRelationService{ |
519 | 522 » » » RoleProvider: &zkRelationService{"s-p", "db"}, |
520 » err = s.t.AddRelation("r-2", &zkRelation{ | 523 » » » RolePeer: &zkRelationService{"s-r", "db"}, |
521 » » Interface: "ifce", | 524 » » }, |
522 » » Scope: ScopeGlobal, | 525 » }) |
523 » » Services: map[RelationRole]string{RoleProvider: "s-p", RoleRequ
irer: "s-r", RolePeer: "s-r"}, | 526 » c.Assert(err, ErrorMatches, `relation has provider but no requirer`) |
524 » }) | 527 |
525 » c.Assert(err, ErrorMatches, `too many services defined`) | 528 » err = s.t.AddRelation("r-6", &zkRelation{ |
526 | 529 » » Interface: "ifce", |
527 » err = s.t.AddRelation("r-2", &zkRelation{ | 530 » » Scope: ScopeGlobal, |
528 » » Interface: "ifce", | 531 » » Services: map[RelationRole]*zkRelationService{ |
529 » » Scope: ScopeGlobal, | 532 » » » RoleProvider: &zkRelationService{"s-p", "db"}, |
530 » » Services: map[RelationRole]string{RoleProvider: "s-p", RoleRequ
irer: "illegal"}, | 533 » » » RoleRequirer: &zkRelationService{"s-r", "db"}, |
| 534 » » » RolePeer: &zkRelationService{"s-r", "db"}, |
| 535 » » }, |
| 536 » }) |
| 537 » c.Assert(err, ErrorMatches, `relation with mixed peer, provider, and req
uirer roles`) |
| 538 |
| 539 » err = s.t.AddRelation("r-7", &zkRelation{ |
| 540 » » Interface: "ifce", |
| 541 » » Scope: ScopeGlobal, |
| 542 » » Services: map[RelationRole]*zkRelationService{ |
| 543 » » » RoleProvider: &zkRelationService{"s-p", "db"}, |
| 544 » » » RoleRequirer: &zkRelationService{"illegal", "db"}, |
| 545 » » }, |
531 }) | 546 }) |
532 c.Assert(err, ErrorMatches, `service with key "illegal" not found`) | 547 c.Assert(err, ErrorMatches, `service with key "illegal" not found`) |
533 | 548 |
534 err = s.t.AddRelation("r-1", &zkRelation{ | 549 err = s.t.AddRelation("r-1", &zkRelation{ |
535 Interface: "ifce", | 550 Interface: "ifce", |
536 Scope: ScopeGlobal, | 551 Scope: ScopeGlobal, |
537 » » Services: map[RelationRole]string{RoleProvider: "s-p", RoleRequ
irer: "s-r"}, | 552 » » Services: map[RelationRole]*zkRelationService{ |
| 553 » » » RoleProvider: &zkRelationService{"s-p", "db"}, |
| 554 » » » RoleRequirer: &zkRelationService{"s-r", "db"}, |
| 555 » » }, |
538 }) | 556 }) |
539 c.Assert(err, ErrorMatches, `relation key "r-1" already in use`) | 557 c.Assert(err, ErrorMatches, `relation key "r-1" already in use`) |
540 } | 558 } |
541 | 559 |
542 func (s *TopologySuite) TestRelationKeys(c *C) { | 560 func (s *TopologySuite) TestRelationKeys(c *C) { |
543 // Check that fetching the relation keys works. | 561 // Check that fetching the relation keys works. |
544 keys := s.t.RelationKeys() | 562 keys := s.t.RelationKeys() |
545 c.Assert(keys, DeepEquals, []string{}) | 563 c.Assert(keys, DeepEquals, []string{}) |
546 | 564 |
547 s.t.AddService("s-p", "riak") | 565 s.t.AddService("s-p", "riak") |
548 s.t.AddRelation("r-1", &zkRelation{ | 566 s.t.AddRelation("r-1", &zkRelation{ |
549 Interface: "ifce", | 567 Interface: "ifce", |
550 Scope: ScopeGlobal, | 568 Scope: ScopeGlobal, |
551 » » Services: map[RelationRole]string{RolePeer: "s-p"}, | 569 » » Services: map[RelationRole]*zkRelationService{ |
| 570 » » » RolePeer: &zkRelationService{"s-p", "cache"}, |
| 571 » » }, |
552 }) | 572 }) |
553 keys = s.t.RelationKeys() | 573 keys = s.t.RelationKeys() |
554 c.Assert(keys, DeepEquals, []string{"r-1"}) | 574 c.Assert(keys, DeepEquals, []string{"r-1"}) |
555 | 575 |
556 s.t.AddRelation("r-2", &zkRelation{ | 576 s.t.AddRelation("r-2", &zkRelation{ |
557 Interface: "ifce", | 577 Interface: "ifce", |
558 Scope: ScopeGlobal, | 578 Scope: ScopeGlobal, |
559 » » Services: map[RelationRole]string{RolePeer: "s-p"}, | 579 » » Services: map[RelationRole]*zkRelationService{ |
| 580 » » » RolePeer: &zkRelationService{"s-p", "cache"}, |
| 581 » » }, |
560 }) | 582 }) |
561 keys = s.t.RelationKeys() | 583 keys = s.t.RelationKeys() |
562 c.Assert(keys, DeepEquals, []string{"r-1", "r-2"}) | 584 c.Assert(keys, DeepEquals, []string{"r-1", "r-2"}) |
| 585 } |
| 586 |
| 587 func (s *TopologySuite) TestRelationsForService(c *C) { |
| 588 // Check that fetching the relations for a service works. |
| 589 s.t.AddService("s-p", "riak") |
| 590 relations, err := s.t.RelationsForService("s-p") |
| 591 c.Assert(err, IsNil) |
| 592 c.Assert(relations, HasLen, 0) |
| 593 |
| 594 s.t.AddRelation("r-0", &zkRelation{ |
| 595 Interface: "ifce0", |
| 596 Scope: ScopeGlobal, |
| 597 Services: map[RelationRole]*zkRelationService{ |
| 598 RolePeer: &zkRelationService{"s-p", "cache"}, |
| 599 }, |
| 600 }) |
| 601 s.t.AddRelation("r-1", &zkRelation{ |
| 602 Interface: "ifce1", |
| 603 Scope: ScopeGlobal, |
| 604 Services: map[RelationRole]*zkRelationService{ |
| 605 RolePeer: &zkRelationService{"s-p", "cache"}, |
| 606 }, |
| 607 }) |
| 608 relations, err = s.t.RelationsForService("s-p") |
| 609 c.Assert(err, IsNil) |
| 610 c.Assert(relations, HasLen, 2) |
| 611 c.Assert(relations["r-0"].Interface, Equals, "ifce0") |
| 612 c.Assert(relations["r-1"].Interface, Equals, "ifce1") |
| 613 |
| 614 s.t.RemoveRelation("r-0") |
| 615 relations, err = s.t.RelationsForService("s-p") |
| 616 c.Assert(err, IsNil) |
| 617 c.Assert(relations, HasLen, 1) |
| 618 c.Assert(relations["r-1"].Interface, Equals, "ifce1") |
563 } | 619 } |
564 | 620 |
565 func (s *TopologySuite) TestRemoveRelation(c *C) { | 621 func (s *TopologySuite) TestRemoveRelation(c *C) { |
566 // Check that removing of a relation works. | 622 // Check that removing of a relation works. |
567 s.t.AddService("s-r", "wordpress") | 623 s.t.AddService("s-r", "wordpress") |
568 s.t.AddService("s-p", "mysql") | 624 s.t.AddService("s-p", "mysql") |
569 | 625 |
570 err := s.t.AddRelation("r-1", &zkRelation{ | 626 err := s.t.AddRelation("r-1", &zkRelation{ |
571 Interface: "ifce", | 627 Interface: "ifce", |
572 Scope: ScopeGlobal, | 628 Scope: ScopeGlobal, |
573 » » Services: map[RelationRole]string{RoleProvider: "s-p", RoleRequ
irer: "s-r"}, | 629 » » Services: map[RelationRole]*zkRelationService{ |
| 630 » » » RoleProvider: &zkRelationService{"s-p", "db"}, |
| 631 » » » RoleRequirer: &zkRelationService{"s-r", "db"}, |
| 632 » » }, |
574 }) | 633 }) |
575 c.Assert(err, IsNil) | 634 c.Assert(err, IsNil) |
576 | 635 |
577 relation, err := s.t.Relation("r-1") | 636 relation, err := s.t.Relation("r-1") |
578 c.Assert(err, IsNil) | 637 c.Assert(err, IsNil) |
579 c.Assert(relation, NotNil) | 638 c.Assert(relation, NotNil) |
580 » c.Assert(relation.Services[RoleProvider], Equals, "s-p") | 639 » c.Assert(relation.Services[RoleProvider].Service, Equals, "s-p") |
581 » c.Assert(relation.Services[RoleRequirer], Equals, "s-r") | 640 » c.Assert(relation.Services[RoleRequirer].Service, Equals, "s-r") |
582 | 641 |
583 s.t.RemoveRelation("r-1") | 642 s.t.RemoveRelation("r-1") |
584 | 643 |
585 relation, err = s.t.Relation("r-1") | 644 relation, err = s.t.Relation("r-1") |
586 c.Assert(relation, IsNil) | 645 c.Assert(relation, IsNil) |
587 c.Assert(err, ErrorMatches, `relation "r-1" does not exist`) | 646 c.Assert(err, ErrorMatches, `relation "r-1" does not exist`) |
588 } | 647 } |
589 | 648 |
590 func (s *TopologySuite) TestRemoveServiceWithRelations(c *C) { | 649 func (s *TopologySuite) TestRemoveServiceWithRelations(c *C) { |
591 // Check that the removing of a service with | 650 // Check that the removing of a service with |
592 // associated relations leads to an error. | 651 // associated relations leads to an error. |
593 s.t.AddService("s-p", "riak") | 652 s.t.AddService("s-p", "riak") |
594 s.t.AddRelation("r-1", &zkRelation{ | 653 s.t.AddRelation("r-1", &zkRelation{ |
595 Interface: "ifce", | 654 Interface: "ifce", |
596 Scope: ScopeGlobal, | 655 Scope: ScopeGlobal, |
597 » » Services: map[RelationRole]string{RolePeer: "s-p"}, | 656 » » Services: map[RelationRole]*zkRelationService{ |
| 657 » » » RolePeer: &zkRelationService{"s-p", "cache"}, |
| 658 » » }, |
598 }) | 659 }) |
599 | 660 |
600 err := s.t.RemoveService("s-p") | 661 err := s.t.RemoveService("s-p") |
601 c.Assert(err, ErrorMatches, `cannot remove service "s-p" with active rel
ations`) | 662 c.Assert(err, ErrorMatches, `cannot remove service "s-p" with active rel
ations`) |
602 } | 663 } |
603 | 664 |
604 func (s *TopologySuite) TestRelationKeyEndpoints(c *C) { | 665 func (s *TopologySuite) TestRelationKeyEndpoints(c *C) { |
605 » mysqlep1 := RelationEndpoint{"mysql", "ifce1", "blog1", RoleProvider, Sc
opeGlobal} | 666 » mysqlep1 := RelationEndpoint{"mysql", "ifce1", "db", RoleProvider, Scope
Global} |
606 » blogep1 := RelationEndpoint{"wordpress", "ifce1", "blog1", RoleRequirer,
ScopeGlobal} | 667 » blogep1 := RelationEndpoint{"wordpress", "ifce1", "db", RoleRequirer, Sc
opeGlobal} |
607 » mysqlep2 := RelationEndpoint{"mysql", "ifce2", "blog2", RoleProvider, Sc
opeGlobal} | 668 » mysqlep2 := RelationEndpoint{"mysql", "ifce2", "db", RoleProvider, Scope
Global} |
608 » blogep2 := RelationEndpoint{"wordpress", "ifce2", "blog2", RoleRequirer,
ScopeGlobal} | 669 » blogep2 := RelationEndpoint{"wordpress", "ifce2", "db", RoleRequirer, Sc
opeGlobal} |
609 » mysqlep3 := RelationEndpoint{"mysql", "ifce3", "blog3", RoleProvider, Sc
opeGlobal} | 670 » mysqlep3 := RelationEndpoint{"mysql", "ifce3", "db", RoleProvider, Scope
Global} |
610 » blogep3 := RelationEndpoint{"wordpress", "ifce3", "blog3", RoleRequirer,
ScopeGlobal} | 671 » blogep3 := RelationEndpoint{"wordpress", "ifce3", "db", RoleRequirer, Sc
opeGlobal} |
611 s.t.AddService("s-r", "wordpress") | 672 s.t.AddService("s-r", "wordpress") |
612 s.t.AddService("s-p", "mysql") | 673 s.t.AddService("s-p", "mysql") |
613 s.t.AddRelation("r-0", &zkRelation{ | 674 s.t.AddRelation("r-0", &zkRelation{ |
614 Interface: "ifce1", | 675 Interface: "ifce1", |
615 Scope: ScopeGlobal, | 676 Scope: ScopeGlobal, |
616 » » Services: map[RelationRole]string{RoleProvider: "s-p", RoleRequ
irer: "s-r"}, | 677 » » Services: map[RelationRole]*zkRelationService{ |
| 678 » » » RoleProvider: &zkRelationService{"s-p", "db"}, |
| 679 » » » RoleRequirer: &zkRelationService{"s-r", "db"}, |
| 680 » » }, |
617 }) | 681 }) |
618 s.t.AddRelation("r-1", &zkRelation{ | 682 s.t.AddRelation("r-1", &zkRelation{ |
619 Interface: "ifce2", | 683 Interface: "ifce2", |
620 Scope: ScopeGlobal, | 684 Scope: ScopeGlobal, |
621 » » Services: map[RelationRole]string{RoleProvider: "s-p", RoleRequ
irer: "s-r"}, | 685 » » Services: map[RelationRole]*zkRelationService{ |
| 686 » » » RoleProvider: &zkRelationService{"s-p", "db"}, |
| 687 » » » RoleRequirer: &zkRelationService{"s-r", "db"}, |
| 688 » » }, |
622 }) | 689 }) |
623 | 690 |
624 // Valid relations. | 691 // Valid relations. |
625 key, err := s.t.RelationKey(mysqlep1, blogep1) | 692 key, err := s.t.RelationKey(mysqlep1, blogep1) |
626 c.Assert(err, IsNil) | 693 c.Assert(err, IsNil) |
627 c.Assert(key, Equals, "r-0") | 694 c.Assert(key, Equals, "r-0") |
628 key, err = s.t.RelationKey(blogep1, mysqlep1) | 695 key, err = s.t.RelationKey(blogep1, mysqlep1) |
629 c.Assert(err, IsNil) | 696 c.Assert(err, IsNil) |
630 c.Assert(key, Equals, "r-0") | 697 c.Assert(key, Equals, "r-0") |
631 key, err = s.t.RelationKey(mysqlep2, blogep2) | 698 key, err = s.t.RelationKey(mysqlep2, blogep2) |
632 c.Assert(err, IsNil) | 699 c.Assert(err, IsNil) |
633 c.Assert(key, Equals, "r-1") | 700 c.Assert(key, Equals, "r-1") |
634 key, err = s.t.RelationKey(blogep2, mysqlep2) | 701 key, err = s.t.RelationKey(blogep2, mysqlep2) |
635 c.Assert(err, IsNil) | 702 c.Assert(err, IsNil) |
636 c.Assert(key, Equals, "r-1") | 703 c.Assert(key, Equals, "r-1") |
637 | 704 |
638 // Endpoints without relation. | 705 // Endpoints without relation. |
639 _, err = s.t.RelationKey(mysqlep3, blogep3) | 706 _, err = s.t.RelationKey(mysqlep3, blogep3) |
640 » c.Assert(err, ErrorMatches, `state: no relation between "provider:blog3:
mysql:ifce3" and "requirer:blog3:wordpress:ifce3"`) | 707 » c.Assert(err, ErrorMatches, `state: no relation between "mysql:db" and "
wordpress:db"`) |
641 | 708 |
642 // Mix of endpoints of two relations. | 709 // Mix of endpoints of two relations. |
643 _, err = s.t.RelationKey(mysqlep1, blogep2) | 710 _, err = s.t.RelationKey(mysqlep1, blogep2) |
644 » c.Assert(err, ErrorMatches, `state: no relation between "provider:blog1:
mysql:ifce1" and "requirer:blog2:wordpress:ifce2"`) | 711 » c.Assert(err, ErrorMatches, `state: no relation between "mysql:db" and "
wordpress:db"`) |
| 712 |
| 713 » // Illegal number of endpoints. |
| 714 » _, err = s.t.RelationKey() |
| 715 » c.Assert(err, ErrorMatches, `state: illegal number of relation endpoints
provided`) |
| 716 » _, err = s.t.RelationKey(mysqlep1, mysqlep2, blogep1) |
| 717 » c.Assert(err, ErrorMatches, `state: illegal number of relation endpoints
provided`) |
645 } | 718 } |
646 | 719 |
647 func (s *TopologySuite) TestRelationKeyIllegalEndpoints(c *C) { | 720 func (s *TopologySuite) TestRelationKeyIllegalEndpoints(c *C) { |
648 » mysqlep1 := RelationEndpoint{"mysql", "ifce", "blog", RoleProvider, Scop
eGlobal} | 721 » mysqlep1 := RelationEndpoint{"mysql", "ifce", "db", RoleProvider, ScopeG
lobal} |
649 » blogep1 := RelationEndpoint{"wordpress", "ifce", "blog", RoleRequirer, S
copeGlobal} | 722 » blogep1 := RelationEndpoint{"wordpress", "ifce", "db", RoleRequirer, Sco
peGlobal} |
650 » mysqlep2 := RelationEndpoint{"illegal-mysql", "ifce", "blog", RoleProvid
er, ScopeGlobal} | 723 » mysqlep2 := RelationEndpoint{"illegal-mysql", "ifce", "db", RoleProvider
, ScopeGlobal} |
651 » blogep2 := RelationEndpoint{"illegal-wordpress", "ifce", "blog", RoleReq
uirer, ScopeGlobal} | 724 » blogep2 := RelationEndpoint{"illegal-wordpress", "ifce", "db", RoleRequi
rer, ScopeGlobal} |
652 riakep3 := RelationEndpoint{"riak", "ifce", "ring", RolePeer, ScopeGloba
l} | 725 riakep3 := RelationEndpoint{"riak", "ifce", "ring", RolePeer, ScopeGloba
l} |
653 s.t.AddService("s-r", "wordpress") | 726 s.t.AddService("s-r", "wordpress") |
654 s.t.AddService("s-p1", "mysql") | 727 s.t.AddService("s-p1", "mysql") |
655 s.t.AddService("s-p2", "riak") | 728 s.t.AddService("s-p2", "riak") |
656 s.t.AddRelation("r-0", &zkRelation{ | 729 s.t.AddRelation("r-0", &zkRelation{ |
657 Interface: "ifce1", | 730 Interface: "ifce1", |
658 Scope: ScopeGlobal, | 731 Scope: ScopeGlobal, |
659 » » Services: map[RelationRole]string{RoleProvider: "s-p1", RoleReq
uirer: "s-r"}, | 732 » » Services: map[RelationRole]*zkRelationService{ |
| 733 » » » RoleProvider: &zkRelationService{"s-p", "db"}, |
| 734 » » » RoleRequirer: &zkRelationService{"s-r", "db"}, |
| 735 » » }, |
660 }) | 736 }) |
661 | 737 |
662 key, err := s.t.RelationKey(mysqlep1, blogep2) | 738 key, err := s.t.RelationKey(mysqlep1, blogep2) |
663 c.Assert(key, Equals, "") | 739 c.Assert(key, Equals, "") |
664 » c.Assert(err, ErrorMatches, `service with name "illegal-wordpress" not f
ound`) | 740 » c.Assert(err, ErrorMatches, `state: no relation between "mysql:db" and "
illegal-wordpress:db"`) |
665 key, err = s.t.RelationKey(mysqlep2, blogep1) | 741 key, err = s.t.RelationKey(mysqlep2, blogep1) |
666 c.Assert(key, Equals, "") | 742 c.Assert(key, Equals, "") |
667 » c.Assert(err, ErrorMatches, `service with name "illegal-mysql" not found
`) | 743 » c.Assert(err, ErrorMatches, `state: no relation between "illegal-mysql:d
b" and "wordpress:db"`) |
668 key, err = s.t.RelationKey(mysqlep1, riakep3) | 744 key, err = s.t.RelationKey(mysqlep1, riakep3) |
669 c.Assert(key, Equals, "") | 745 c.Assert(key, Equals, "") |
670 » c.Assert(err, ErrorMatches, `state: no relation between "provider:blog:m
ysql:ifce" and "peer:ring:riak:ifce"`) | 746 » c.Assert(err, ErrorMatches, `state: no relation between "mysql:db" and "
riak:ring"`) |
671 } | 747 } |
672 | 748 |
673 func (s *TopologySuite) TestPeerRelationKeyEndpoints(c *C) { | 749 func (s *TopologySuite) TestPeerRelationKeyEndpoints(c *C) { |
674 riakep1 := RelationEndpoint{"riak", "ifce1", "ring", RolePeer, ScopeGlob
al} | 750 riakep1 := RelationEndpoint{"riak", "ifce1", "ring", RolePeer, ScopeGlob
al} |
675 riakep2 := RelationEndpoint{"riak", "ifce2", "ring", RolePeer, ScopeGlob
al} | 751 riakep2 := RelationEndpoint{"riak", "ifce2", "ring", RolePeer, ScopeGlob
al} |
676 riakep3 := RelationEndpoint{"riak", "ifce3", "ring", RolePeer, ScopeGlob
al} | 752 riakep3 := RelationEndpoint{"riak", "ifce3", "ring", RolePeer, ScopeGlob
al} |
| 753 s.t.AddService("s-p", "ring") |
| 754 s.t.AddRelation("r-0", &zkRelation{ |
| 755 Interface: "ifce1", |
| 756 Scope: ScopeGlobal, |
| 757 Services: map[RelationRole]*zkRelationService{ |
| 758 RolePeer: &zkRelationService{"s-p", "ring"}, |
| 759 }, |
| 760 }) |
| 761 s.t.AddRelation("r-1", &zkRelation{ |
| 762 Interface: "ifce2", |
| 763 Scope: ScopeGlobal, |
| 764 Services: map[RelationRole]*zkRelationService{ |
| 765 RolePeer: &zkRelationService{"s-p", "ring"}, |
| 766 }, |
| 767 }) |
| 768 |
| 769 // Valid relations. |
| 770 key, err := s.t.RelationKey(riakep1) |
| 771 c.Assert(err, IsNil) |
| 772 c.Assert(key, Equals, "r-0") |
| 773 key, err = s.t.RelationKey(riakep2) |
| 774 c.Assert(err, IsNil) |
| 775 c.Assert(key, Equals, "r-1") |
| 776 |
| 777 // Endpoint without relation. |
| 778 key, err = s.t.RelationKey(riakep3) |
| 779 c.Assert(err, ErrorMatches, `state: no peer relation for "riak:ring"`) |
| 780 } |
| 781 |
| 782 func (s *TopologySuite) TestPeerRelationKeyIllegalEndpoints(c *C) { |
| 783 riakep1 := RelationEndpoint{"riak", "ifce", "illegal-ring", RolePeer, Sc
opeGlobal} |
677 s.t.AddService("s-p", "riak") | 784 s.t.AddService("s-p", "riak") |
678 s.t.AddRelation("r-0", &zkRelation{ | 785 s.t.AddRelation("r-0", &zkRelation{ |
679 » » Interface: "ifce1", | 786 » » Interface: "ifce", |
680 » » Scope: ScopeGlobal, | 787 » » Scope: ScopeGlobal, |
681 » » Services: map[RelationRole]string{RolePeer: "s-p"}, | 788 » » Services: map[RelationRole]*zkRelationService{ |
682 » }) | 789 » » » RolePeer: &zkRelationService{"s-p", "ring"}, |
683 » s.t.AddRelation("r-1", &zkRelation{ | 790 » » }, |
684 » » Interface: "ifce2", | 791 » }) |
685 » » Scope: ScopeGlobal, | 792 |
686 » » Services: map[RelationRole]string{RolePeer: "s-p"}, | 793 » key, err := s.t.RelationKey(riakep1) |
687 » }) | |
688 | |
689 » // Valid relations. | |
690 » key, err := s.t.PeerRelationKey(riakep1) | |
691 » c.Assert(err, IsNil) | |
692 » c.Assert(key, Equals, "r-0") | |
693 » key, err = s.t.PeerRelationKey(riakep2) | |
694 » c.Assert(err, IsNil) | |
695 » c.Assert(key, Equals, "r-1") | |
696 | |
697 » // Endpoint without relation. | |
698 » key, err = s.t.PeerRelationKey(riakep3) | |
699 » c.Assert(err, ErrorMatches, `state: no peer relation for "peer:ring:riak
:ifce3"`) | |
700 } | |
701 | |
702 func (s *TopologySuite) TestPeerRelationKeyIllegalEndpoints(c *C) { | |
703 » riakep1 := RelationEndpoint{"illegal-riak", "ifce", "ring", RolePeer, Sc
opeGlobal} | |
704 » s.t.AddService("s-p", "riak") | |
705 » s.t.AddRelation("r-0", &zkRelation{ | |
706 » » Interface: "ifce", | |
707 » » Scope: ScopeGlobal, | |
708 » » Services: map[RelationRole]string{RolePeer: "s-p"}, | |
709 » }) | |
710 | |
711 » key, err := s.t.PeerRelationKey(riakep1) | |
712 c.Assert(key, Equals, "") | 794 c.Assert(key, Equals, "") |
713 » c.Assert(err, ErrorMatches, `service with name "illegal-riak" not found`
) | 795 » c.Assert(err, ErrorMatches, `state: no peer relation for "riak:illegal-r
ing"`) |
714 } | 796 } |
715 | 797 |
716 type ConfigNodeSuite struct { | 798 type ConfigNodeSuite struct { |
717 zkServer *zookeeper.Server | 799 zkServer *zookeeper.Server |
718 zkTestRoot string | 800 zkTestRoot string |
719 zkTestPort int | 801 zkTestPort int |
720 zkAddr string | 802 zkAddr string |
721 zkConn *zookeeper.Conn | 803 zkConn *zookeeper.Conn |
722 path string | 804 path string |
723 } | 805 } |
(...skipping 319 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1043 // Shouldn't write again. Changes were already | 1125 // Shouldn't write again. Changes were already |
1044 // flushed and acted upon by other parties. | 1126 // flushed and acted upon by other parties. |
1045 changes, err = nodeOne.Write() | 1127 changes, err = nodeOne.Write() |
1046 c.Assert(err, IsNil) | 1128 c.Assert(err, IsNil) |
1047 c.Assert(changes, DeepEquals, []ItemChange{}) | 1129 c.Assert(changes, DeepEquals, []ItemChange{}) |
1048 | 1130 |
1049 err = nodeOne.Read() | 1131 err = nodeOne.Read() |
1050 c.Assert(err, IsNil) | 1132 c.Assert(err, IsNil) |
1051 c.Assert(nodeOne, DeepEquals, nodeTwo) | 1133 c.Assert(nodeOne, DeepEquals, nodeTwo) |
1052 } | 1134 } |
1053 | |
1054 type QuoteSuite struct{} | |
1055 | |
1056 var _ = Suite(&QuoteSuite{}) | |
1057 | |
1058 func (s *QuoteSuite) TestUnmodified(c *C) { | |
1059 // Check that a string containig only valid | |
1060 // chars stays unmodified. | |
1061 in := "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789.-" | |
1062 out := Quote(in) | |
1063 c.Assert(out, Equals, in) | |
1064 } | |
1065 | |
1066 func (s *QuoteSuite) TestQuote(c *C) { | |
1067 // Check that invalid chars are translated correctly. | |
1068 in := "hello_there/how'are~you-today.sir" | |
1069 out := Quote(in) | |
1070 c.Assert(out, Equals, "hello_5f_there_2f_how_27_are_7e_you-today.sir") | |
1071 } | |
LEFT | RIGHT |