Esempio n. 1
0
 public function testCacheWritten()
 {
     $ec2 = new Ec2MetadataGetter("/tmp");
     $ec2->allowDummy();
     $response = $ec2->getMultiple(['AmiId']);
     $this->assertEquals('ami-12345678', $response['AmiId']);
     $cacheContent = file_get_contents('/tmp/fd2f4b29d4b9a6c68c2669d66aacd03dffa6164b.json');
     $this->assertEquals('{"AmiId":"ami-12345678"}', $cacheContent);
 }
Esempio n. 2
0
 public function testDummyMultiple()
 {
     $ec2 = new Ec2MetadataGetter("/tmp");
     $ec2->allowDummy();
     $data = $ec2->getMultiple(['Network', 'AmiId']);
     $interface = $data['Network']['11:22:33:44:55:66'];
     $this->assertEquals($interface['public-ipv4s'], '12.34.56.78');
     $this->assertEquals('ami-12345678', $data['AmiId']);
 }
 /**
  * write metadata to Virtual File System
  *
  * @param array $metadata
  * @param string $hostname
  */
 public function __construct(array $metadata, $hostname = '')
 {
     parent::__construct();
     $this->vfsRoot = \org\bovigo\vfs\vfsStream::setup(empty($hostname) ? $this->hostname : $hostname);
     $file = \org\bovigo\vfs\vfsStream::newFile('latest');
     $file->write('dynamic' . PHP_EOL . 'meta-data' . PHP_EOL . 'user-data');
     $this->vfsRoot->addChild($file);
     if (array_key_exists('block-device-mapping', $metadata)) {
         $this->writeBlockDeviceMappingToVfs($metadata['block-device-mapping']);
         unset($metadata['block-device-mapping']);
     }
     if (array_key_exists('public-keys', $metadata)) {
         $this->writePublicKeysToVfs($metadata['public-keys']);
         unset($metadata['public-keys']);
     }
     if (array_key_exists('network/interfaces/macs', $metadata)) {
         $this->writeNetworkToVfs($metadata['network/interfaces/macs']);
         unset($metadata['network/interfaces/macs']);
     }
     if (array_key_exists('user-data', $metadata)) {
         $file = \org\bovigo\vfs\vfsStream::newFile('latest/user-data');
         $file->write($metadata['user-data']);
         $this->vfsRoot->addChild($file);
         unset($metadata['user-data']);
     }
     $this->writeArrayToVfs($metadata, $this->getMetadataPath());
 }