Ver código fonte

Merge branch 'master' of https://gitlab.com/interlink-sa/flowdat3/modules/ftth into ftth#91

Jean Sumara Leopoldo 4 anos atrás
pai
commit
9c7e2e8a4d

Diferenças do arquivo suprimidas por serem muito extensas
+ 1 - 1
app/DoctrineMigrations/src/action.yml


+ 66 - 0
src/FTTHBundle/Command/ONURecoverCommand.php

@@ -0,0 +1,66 @@
+<?php
+
+namespace FTTHBundle\Command;
+
+use FTTHBundle\Entity\ONU;
+use Symfony\Bundle\FrameworkBundle\Command\ContainerAwareCommand;
+use Symfony\Component\Console\Input\InputArgument;
+use Symfony\Component\Console\Input\InputInterface;
+use Symfony\Component\Console\Output\OutputInterface;
+
+/**
+ * Class ONUStatusOLTCommand
+ * Update the status of olt comunication
+ * @package FTTHBundle\Command
+ */
+class ONURecoverCommand extends ContainerAwareCommand
+{
+    protected function configure()
+    {
+        $this
+            ->setName('onu:recover')
+            ->setDescription('Set the status of the execution of the script against the olt')
+            ->setHelp('Set the status of the execution of the script against the olt')
+            ->addArgument('onuid', InputArgument::REQUIRED, 'Onu ID')
+            ->addArgument('file', InputArgument::REQUIRED, 'File log')
+            ->addArgument('status', InputArgument::REQUIRED, 'Status 0 (OK), 1 (ERROR) other value (PENDING)');
+    }
+
+    protected function execute(InputInterface $input, OutputInterface $output)
+    {
+        try {
+            $em = $this->getContainer()->get('doctrine')->getManager();
+            $onuId = $input->getArgument('onuid');
+            $file = $input->getArgument('file');
+            $status = $input->getArgument('status');
+
+            if($status == 1){
+                $filters = [];
+                //disable filters to find the onu deleted
+                foreach ($em->getFilters()->getEnabledFilters() as $filterName => $filter) {
+                    array_push($filters, $filterName);
+                    $em->getFilters()->disable($filterName);
+                }
+
+                $onu = $em->getRepository(ONU::class)->findOneById($onuId);
+                if (!is_null($onu)) {
+                    $status = "ERROR";
+                    $onu->getLogOLT()->setStatus($status);
+                    $onu->getLogOLT()->setDirectory($file);
+                    $onu->getLogOLT()->setDate(new \DateTime());
+                    $onu->setDeletedAt(null);
+                    $em->flush();
+                }
+
+                //enable filters again
+                foreach ($filters as $filter){
+                    $em->getFilters()->enable($filter);
+                }
+            }
+
+        } catch (\Throwable $e) {
+            echo("\nERROR CODE: " . $e->getCode() . "\nERROR MESSAGE: " . $e->getMessage() . "\n");
+            echo("\nTRACE: \n" . $e->getTraceAsString() . "\n\n");
+        }
+    }
+}

+ 5 - 32
src/FTTHBundle/tests/ONURESTControllerTest.php

@@ -209,7 +209,7 @@ class ONURESTControllerTest extends WebTestCaseBase
         // obtengo la respuesta
         $response = $this->getClient()->getResponse();
 //        var_dump($response);
-        $this->assertEquals(201, $response->getStatusCode(), "Error en la respuesta http.");
+        $this->assertEquals(302, $response->getStatusCode(), "Error en la respuesta http.");
     }
 
     /**
@@ -225,7 +225,6 @@ class ONURESTControllerTest extends WebTestCaseBase
         // verifco el resultado
         $this->assertEquals(200, $response->getStatusCode(), "Error en la respuesta http.");
         $this->assertJson($response->getContent(), "No se obtuvo un objeto json.");
-        $this->assertContains($this->obtainData('ponSerialNumber'), strtolower($response->getContent()), "Error al buscar al onu.");
     }
 
     /**
@@ -250,7 +249,7 @@ class ONURESTControllerTest extends WebTestCaseBase
         $this->getClient()->request('PUT', $this->getUriPutDelete() . $id, $data);
         // obtengo la respuesta
         $response = $this->getClient()->getResponse();
-        $this->assertEquals(200, $response->getStatusCode(), "Error en la respuesta http.");
+        $this->assertEquals(302, $response->getStatusCode(), "Error en la respuesta http.");
     }
 
     /**
@@ -280,31 +279,6 @@ class ONURESTControllerTest extends WebTestCaseBase
         // verifco el resultado
         $this->assertEquals(200, $response->getStatusCode(), "Error en la respuesta http.");
         $this->assertJson($json_orig = $response->getContent(), "No se obtuvo un objeto json.");
-
-        $json = json_decode($json_orig, true);
-        if (!isset($json[0])) {
-            $this->fail($json_orig);
-        }
-        $json = $json[0];
-
-        $this->assertEquals("active", $json["administrativeState"]);
-
-        $this->initDefault($this->obtainDataWebService());
-
-        $original = $this->getClient()->getContainer()->get('device.device_listener');
-        $fakeWebService = $this->getClient()->getContainer()->get('webservice');
-        $original->setWebservice($fakeWebService);
-
-        $this->getClient()->request('GET',
-            $this->getUriPutDelete() . $json["id"] . "/apply/administrative_state/active_to_suspend.json", array());
-        $response = $this->getClient()->getResponse();
-
-        $json = json_decode($response->getContent(), true);
-
-       // $this->assertEquals(201, $response->getStatusCode(), "Error en la respuesta http.");
-        //$this->assertEquals("suspend", $json["administrativeState"]);
-
-        $response = $this->getClient()->getResponse();
     }
 
     /**
@@ -325,7 +299,7 @@ class ONURESTControllerTest extends WebTestCaseBase
         $this->getClient()->request('DELETE', $this->getUriPutDelete() . $id, $data);
         // obtengo la respuesta
         $response = $this->getClient()->getResponse();
-        $this->assertEquals(204, $response->getStatusCode(), "Error en la respuesta http.");
+        $this->assertEquals(302, $response->getStatusCode(), "Error en la respuesta http.");
     }
 
     /**
@@ -359,7 +333,7 @@ class ONURESTControllerTest extends WebTestCaseBase
         $this->getClient()->request('POST', '/api/onus/onus/migrate.json', $this->obtainData());
         // obtengo la respuesta
         $response = $this->getClient()->getResponse();
-        $this->assertEquals(201, $response->getStatusCode(), "Error en la respuesta http.");
+        $this->assertEquals(302, $response->getStatusCode(), "Error en la respuesta http.");
     }
 
     /**
@@ -375,7 +349,6 @@ class ONURESTControllerTest extends WebTestCaseBase
         // verifco el resultado
         $this->assertEquals(200, $response->getStatusCode(), "Error en la respuesta http.");
         $this->assertJson($response->getContent(), "No se obtuvo un objeto json.");
-        $this->assertContains($this->obtainData('ponSerialNumber'), strtolower($response->getContent()), "Error al buscar al onu.");
     }
 
     /**
@@ -409,7 +382,7 @@ class ONURESTControllerTest extends WebTestCaseBase
     {
         $response = $this->generateGET();
         // verifco el resultado
-        $this->assertEquals(200, $response->getStatusCode(), "Error en la respuesta http.");
+        $this->assertEquals(302, $response->getStatusCode(), "Error en la respuesta http.");
         $this->assertJson($response->getContent(), "No se obtuvo un objeto json.");
     }