robot framework string row comparison - robotframework

I am new to robot framework.
I have two strings:
${str1}:
C 100.1.12.0/29 is directly connected, Ethernet0/1
L 100.1.12.1/32 is directly connected, Ethernet0/1
C 100.1.13.0/29 is directly connected, Ethernet0/2
L 100.1.13.1/32 is directly connected, Ethernet0/2
C 172.16.166.0/24 is directly connected, Ethernet0/0
L 172.16.166.151/32 is directly connected, Ethernet0/0
C 192.168.1.3 is directly connected, Loopback3
C 192.168.11.2 is directly connected, Loopback1
C 192.168.11.3 is directly connected, Loopback2
${str2}:
C 200.1.12.0/29 is directly connected, Ethernet0/1
L 200.1.12.1/32 is directly connected, Ethernet0/1
C 200.1.13.0/29 is directly connected, Ethernet0/2
L 100.1.13.1/32 is directly connected, Ethernet0/2
C 172.16.166.0/24 is directly connected, Ethernet0/0
L 172.16.166.151/32 is directly connected, Ethernet0/0
C 192.168.1.3 is directly connected, Loopback3
C 192.168.11.2 is directly connected, Loopback1
C 192.168.11.3 is directly connected, Loopback2
I've to compare and see if any of the IP address of {str2} are in {str1}. how to do that? can you guys help me with example please? is there a way to treat each row as row in this string?

Related

How to Trigger a Task based on previous task status?

I have 4 tasks as shown below. I want Task D to be triggered even if Task C has Failed or Succeeded. However, Task C or Task D should not be triggered if Task A or Task B has failed.
I tried to use trigger rule = all_done for Task D but if Task B fails, it triggers Task D as well.
Is there a way to accomplish this in Airflow?
In your case, B is the critical task, and C is non-critical, but you want it to at least make an attempt before D.
First you need to remove all the trigger rules you have applied.
You currently have all_done on C, which means that C runs even when B fails -- which you don't want.
Next you need to add a dependency between B and D:
task_b >> task_d
Now B and C are each independently upstream of D.
So what remains are two problems:
D must not run if B fails
D must not run until C is done
You can't do one_success because the important one is B and it's not enough if C alone succeeds.
What you need is "B success and C done".
A relatively clean way to do this is to make C "skip" instead of fail if an error is encountered.
Here's an example of how to do that:
class MySkippingDummyOperator(DummyOperator):
def execute(self, context):
try:
super().execute(context)
except Exception as e:
raise AirflowSkipException(f'skipping instead of failing.')
If MySkippingDummyOperator encounters an error, the task will end in skipped state.
So B is success / fail, and C is success / skip. With this behavior we can use trigger rule none_failed on task D.
none_failed means everything completed and nothing failed.
And this should produce the desired behavior:
if B is unsuccessful, then D can't run
if C is unsuccessful, it will only be a skip, so D can still run
D will not run unless both B and C are done
Alternatively, you could let D use all_done, and then from within D retrieve the task instance state of B and then skip D if B failed. But this is more complicated and certainly more of a hack.

Gremlin - Using an OR step to get different types of connected vertices

So I have a graph schema where vertex type A can connect inwards to vertex type B or type C in a one to many relationship. I'm trying to write a query that outputs any of those relationships if they exist, for instance a sample output would be:
Type A | Type B | Type C
Sample1A,'', Sample1C
Sample2A, Sample2B, ''
Sample3A, Sample3B, Sample3C
Sample4A, 'Sample4Ba, Sample4Bb', Sample4C
The fourth example is if A is connected to multiple B types. If B and C don't exist, then nothing is output.
So far I have the query: g.V().hasLabel('A').as('A').in('connect').hasLabel('B').as('B').or().in('connect').hasLabel('C').as('C').select('A','B','C')
But this query only returns the A vertices without any B's or C's.
Using AWS Neptune if that matters.
As kevin mentioned in the comment, you can use .project() method for this scenario.
g.V().hasLabel("A").as("A").project("a","b", "c")
.by(select("A"))
.by(choose(in("connect").hasLabel("B").count().is(0), constant("NO_B").value(), in("connect").hasLabel("B")))
.by(choose(in("connect").hasLabel("C").count().is(0), constant("NO_C").value() , in("connect").hasLabel("C")));
Your or() steps are not returning a result as written. You could simplify the query as follows:
g.V().hasLabel('A').as('A').in('connect').hasLabel(within('B','C').as('B').select('A','B')
This avoids using select('A','B','C') as only one of 'B' or 'C' will have a result in the or() case.
Here is a version that still uses or()
g.V().hasLabel('A').as('A').in().or(hasLabel('B'),hasLabel('C')).as('B').select('A','B')

How do I run a single task in an Airflow DAG more than once?

So I have 2 paths and step A and C checks for updates and do some transformations in databases and step E unload a query to an artifact file.
A -> B ->
--> E
C -> D ->
Now I want step E to run when:
1) Step A and B are completed
or
2) Step C and D are completed
I tried to use trigger_rule 'one_success' in step E, but the problem is that if step A starts just before step C, step E will only run once and the data change in C is not unloaded to the final artifact, missing the desired SLA.
Is there a way in Airflow to force a step to execute once any parent task finish executing, regardless whether it has already been executed? It seems like this is a very logical and common use case, but searching the documentation doesn't yield me anything.

Copying Functions Across Networks

Using Go, I am trying to write code to transfer a closure across a network from computer A to computer B to allow computer B to execute the closure. For example
Computer A:
c1 := func() { fmt.Println("Hello World") }
// somehow transfer c1 to Computer B
Computer B:
c2 := // receive closure from Computer A
c2()
With the result being to print "Hello World" on the second computer. Is anybody aware of a method for this?
You cannot do this. At least not until some fancy NaCl support is added.

Confusion in reversing a linked list through recursion? [duplicate]

This question already has answers here:
Closed 10 years ago.
Possible Duplicate:
Linked list recursive reverse
I searched my question on SO and got a link
recursion stack trace
I din't understand How the head_ref is Pointing to 4 there?
Could anyone help me to understand this?
ok, first of all, it's 6 am here, and i couldn't sleep all night ... so this might be bullshit ;) ... but here we go:
the "magic" happens at recursiveReverse(&rest); ... the & says that the parameter is the address of rest ... since rest itself is a pointer, our param is a pointer to a pointer ...
when the function has finished, the pointer has been changed, and points to the first element of the reversed sub-list (which is the 4-Node) ...
EX:
so let's say we have our list 1 -> 2 -> 3 -> 4 and have called recursiveReverse(struct node** head_ref) with a pointer to a pointer to the 1-node as the head_ref parameter
so let's say head_ref is at a certain address (which i call A)
head_ref is a pointer to a pointer ... so the value at the address A is another address (let's call that B)
so the "thing" that is stored at B is a pointer ... so the value at B is also an address (let's call that address C)
finally the "thing" stored at C is our struct ...
now with this in mind, we make our first recursive call to recursiveReverse(struct node** head_ref) ... this time our parameter is &rest ... &rest is a pointer to a pointer to the 2-node...
let's have a closer look ... the value of &rest is an address ... (hard to guess, we call that D) ... the value at D is an address (the address of the 2-node) which we call E
after the recursive call has finished, the sub-list 2 -> 3 -> 4 has been reversed (4 -> 3 -> 2), and one of our addresses has been updated with a new value ... D has been updated, and no longer holds the address E, but the address of the 4-node (call that F if you want ...)
so now, we have the pointer "first" pointing to the 1-node which has its next-pointer still pointing at the 2-node... so with first->next->next = first, we correct the 2-nodes "next" pointer, to point at the 1-node ...
since the 1-node shall no longer point to the 2-node, we have first->next=NULL and now the complete list has been reversed ...
since we have no return value, we return our reversed list by the pointer to pointer parameter head_ref ... with *head_ref = rest
rest is a pointer ... it's located at address D ... the current value at D is F (address of the 4-node)
so we write the value of D (which is F, the address of the 4-node) to the Address B (which is *head_ref)
and that is how the pointer to the 4-node is returned

Resources